My Wiki

July 5, 2006

I get “log4j:WARN No appenders could be found for logger” message

Filed under: Log4j — jaikiran @ 7:57 am

While using log4j in your application, sometimes you might encounter the following message:

log4j:WARN No appenders could be found for logger(somePackageName.someClassName).
log4j:WARN Please initialize the log4j system properly.

The reason why you see this message is that your log4j configuration file(i.e. log4j.xml or log4j.properties) is NOT found in the classpath. Placing the log4j configuration file in the applications classpath should solve the issue. If you want to find out how log4j tries to configure itself, have a look at my earlier post :

Know how log4j tries to configure itself

About these ads

46 Comments »

  1. Thanks!! Works now!

    Comment by Robert — February 14, 2008 @ 4:07 pm

  2. Does it always need to be in the classpath? My Java app lets you specify ( as a CLI parameter ) the location of the XML formatted Log4j config file, which could be literally anywhere. If it had to be on the classpath, that would really eliminate the flexibility that I built into the application.

    Comment by John — June 3, 2008 @ 2:16 pm

    • Hi, I’d like to access log4j.properties file without putting it on my classpath. How can I achieve this. I am literaly stuck with fixing this problem

      Comment by Boipelo — June 2, 2011 @ 8:45 am

  3. This was helpful, thanks!

    Comment by Jon Schneider — September 4, 2008 @ 1:48 pm

  4. Thanks dude. That was really helpful.

    Comment by John Dondapati — November 4, 2008 @ 9:02 pm

  5. What if you are using log4j in multiple open source packages and your own code and only one of them is complaining?
    log4j:WARN No appenders could be found for logger (org.hibernate.mapping.RootClass).
    log4j:WARN Please initialize the log4j system properly.

    Comment by Dave — November 12, 2008 @ 4:48 pm

  6. Dave,
    This is probably because the Hibernate logger is not defined in your log4j.xml. (or which ever method you use to load your log4j configuration)

    Comment by Pramod — January 13, 2009 @ 6:23 pm

  7. put my log4j.xml and log4j.properties to my CLASSPATH, but it doesn’t work:

    Buildfile: build.xml
    log4j:WARN No appenders could be found for logger (org.apache.tools.ant).
    log4j:WARN Please initialize the log4j system properly.

    BUUILD FAILED
    …taskdef A class needed by class …class cannot be found : …class

    can you help me?

    Comment by student — January 22, 2009 @ 2:04 pm

  8. Use: DOMConfigurator.configure(“./log4j.xml”); or PropertyConfigurator.configure(“./log4j.properties”);
    Greetings from Lublin@Poland

    Comment by Mariusz — February 12, 2009 @ 8:31 am

  9. Mar 24, 2009 5:06:32 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
    WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property ‘source’ to ‘org.eclipse.jst.jee.server:cards’ did not find a matching property.
    Mar 24, 2009 5:06:32 PM org.apache.catalina.core.AprLifecycleListener init
    INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Intel\DMIX;C:\apache2triad\bin;C:\apache2triad\perl\bin;C:\apache2triad\php\bin;C:\apache2triad\mysql\bin;C:\apache2triad\opssl\bin;C:\apache2triad\python\bin;C:\apache2triad\pgsql\bin;C:\apache2triad\php\extensions;C:\PROGRA~1\SECUREFX;C:\mysql\bin;
    Mar 24, 2009 5:06:32 PM org.apache.coyote.http11.Http11Protocol init
    INFO: Initializing Coyote HTTP/1.1 on http-8080
    Mar 24, 2009 5:06:32 PM org.apache.catalina.startup.Catalina load
    INFO: Initialization processed in 571 ms
    Mar 24, 2009 5:06:32 PM org.apache.catalina.core.StandardService start
    INFO: Starting service Catalina
    Mar 24, 2009 5:06:32 PM org.apache.catalina.core.StandardEngine start
    INFO: Starting Servlet Engine: Apache Tomcat/6.0.18
    Mar 24, 2009 5:06:33 PM org.apache.coyote.http11.Http11Protocol start
    INFO: Starting Coyote HTTP/1.1 on http-8080
    Mar 24, 2009 5:06:33 PM org.apache.jk.common.ChannelSocket init
    INFO: JK: ajp13 listening on /0.0.0.0:8009
    Mar 24, 2009 5:06:33 PM org.apache.jk.server.JkMain start
    INFO: Jk running ID=0 time=0/31 config=null
    Mar 24, 2009 5:06:33 PM org.apache.catalina.startup.Catalina start
    INFO: Server startup in 992 ms

    Comment by QA — March 24, 2009 @ 12:07 pm

  10. Sometimes, even placing log4j.properties and log4j.xml in the classpath doesn’t fix it.

    I finally got the darn thing to shut up when I added this to my initialization code:

    BasicConfigurator.configure();
    Logger.getLogger(“org.apache”).setLevel(Level.INFO);

    Comment by Alex — July 25, 2009 @ 4:25 pm

  11. Thanks, but it does not solve the problem

    Comment by Emily — September 14, 2009 @ 6:03 am

    • Did you get an answer on how to add the log4j.xml to your classpath?

      Comment by aschwin — November 19, 2009 @ 9:25 am

  12. Hey ,
    That was helpful. How to add the xml or the properties file to class path if I am using Eclipse IDE ?

    Thanks,
    -tapas

    Comment by Tapas Adhikary — October 14, 2009 @ 11:11 am

  13. thx it helped me…

    Comment by dinesh chettri — October 23, 2009 @ 4:53 am

  14. thx it helped me….

    Comment by dinesh chettri — October 23, 2009 @ 4:53 am

  15. For what it is worth, to pickup the log4j properties file from a file, and not the classpath, the following arguments should be sent as arguments to your Java command:
    -Dlog4j.configuration=log4jfilename -Dconfig.location=file

    (The second argument is the important one, this tells it to look for it in a file, as opposed to if you switch it to “classpath” which will look for it in your classpath – ie. -Dconfig.location=classpath ).

    Good luck.

    Comment by Mike Wolfson — January 7, 2010 @ 8:56 pm

    • I found that -Dlog4j.configuration=log4jfilename -Dconfig.location=file

      did not work for me, but its close relative:

      -Dlog4j.configuration=file:///usr/zeus/log4j.properties

      did work for me (using URL format)

      Comment by Andrew McGregor — February 11, 2010 @ 3:02 pm

      • Thank you.

        Comment by Scott — November 4, 2010 @ 11:03 pm

      • -Dlog4j.configuration=file:///usr/zeus/log4j.properties

        thanks man.. u made my day…
        really helptull

        Comment by sanjay — March 21, 2011 @ 9:05 am

  16. Thanks, dude! You helped me a lot!

    Comment by alsantos — April 19, 2010 @ 10:21 pm

  17. in my case, the log4j configuration is log4j.xml
    just add in the source below in initialize process such as in main so log4j able to find the configuration

    DOMConfigurator.configure(“log4j.xml”);

    Comment by indra — April 28, 2010 @ 7:54 am

  18. Andrew McGregor, u are my HERO dude!!

    Comment by Luane — June 2, 2010 @ 9:48 am

  19. Another way is set the enviroment property
    -Dlog4j.configuration=”file:conf/log4j.properties” and -Dlog4j.debug=true is usefull too.
    Note the prefix “file:”, it’s very important without doesn’t work.

    Comment by Morto Enterrado — June 16, 2010 @ 8:45 pm

  20. Thanks, it is very useful…

    Comment by madhusudan naik — June 24, 2010 @ 1:58 pm

  21. Thank you, Andrew McGregor; finest solution to this somehow stupid problem.

    Comment by Dacian — July 2, 2010 @ 8:40 am

  22. I guess, it will solve this problem if you fully qualify the class…

    for example,

    private static Logger log = Logger.getLogger(“com.fmr.fims.deconv.XrefCnvThread.class”);

    instead of just private static Logger log = Logger.getLogger(“XrefCnvThread.class”);

    Comment by hh — July 15, 2010 @ 6:52 pm

    • Ignore the quotes in getLogger

      Comment by hh — July 15, 2010 @ 6:55 pm

  23. thanks it works.

    Comment by guvenc — October 23, 2010 @ 10:23 am

  24. dd

    Comment by a — February 2, 2011 @ 1:04 pm

  25. it works, thanks a lot.

    1. The last line shows that the log4.properties is not found in the classpath. You mention that you are using Eclipse. I guess you have not placed the log4j.properties (or log4j.xml) at the right place in the project. If you have project created in D:\MySampleApp folder, then place the log4j.properties (or log4j.xml) at the root of the project (i.e. directly in D:\MySampleApp…

    2. put your class definition into console appender in log4j.xml as

    Comment by guvenc — May 3, 2011 @ 2:16 am

  26. 2. put your class definition into console appender in log4j.xml as

    Comment by guvenc — May 3, 2011 @ 2:17 am

  27. Thanks for the posts. It solved the log4j issue.

    Comment by Asif Shahzad — December 12, 2011 @ 12:45 pm

  28. avoiding having a blank log4j.cfg file helped here

    Comment by Roger Deloy Pack — March 2, 2012 @ 4:34 pm

  29. Hi,
    I am facing issue with log4j as i have implemented log4j in my project and when i run this project from Eclipse its working as expected and logs are printed on my log file, but when i tried to run the same project from Command Prompt by ANT, noting is printed on the log file.
    here is my log4j.properties file

    #Application Logs
    log4j.logger.devpinoyLogger=DEBUG, dest1
    log4j.appender.dest1=org.apache.log4j.RollingFileAppender
    log4j.appender.dest1.maxFileSize=5000KB
    log4j.appender.dest1.maxBackupIndex=3
    log4j.appender.dest1.layout=org.apache.log4j.PatternLayout
    log4j.appender.dest1.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss} %c %m%n
    log4j.appender.dest1.File=E:\\work\\TestFramwork\\Application.log

    log4j.appender.dest1.Append=true

    and in my base class i have created the object.
    Logger APP_LOGS = Logger.getLogger(“devpinoyLogger”);

    can you please suggest me like what is problem with this while running from cmd..

    Thanks in Advance.

    Comment by pawan — March 20, 2012 @ 11:15 am

  30. Thankd Andrew McGregor! It works great!

    Comment by swetha — April 30, 2012 @ 6:43 pm

  31. I’m going to try and use Anrew McGregor’s solution, but what I am not sure what I should put as the file name. For example, I have a log4j.properties file at the root of my app’s folder, so should the path be -Dlog4j.configuration=”file:/log4j.properties” ?

    Comment by Nate — May 17, 2012 @ 12:36 pm

  32. thanks(:::

    Comment by Murali — September 10, 2012 @ 1:33 pm

  33. An explanation just so simple!!.. I can’t found the answer to this problem.. thanks!!!

    Comment by kike — April 13, 2013 @ 9:00 pm

  34. -Dlog4j.debug=true go for this

    Comment by azhar — May 5, 2013 @ 6:33 am

  35. Thanks for a marvelous posting! I definitely enjoyed reading it, you could be a great author.
    I will ensure that I bookmark your blog and will eventually come back sometime soon.
    I want to encourage yourself to continue your great posts, have a nice weekend!

    Comment by informacja bik — May 5, 2013 @ 8:52 pm

  36. Hello, i read your blog from time to time and i own a similar one
    and i was just curious if you get a lot of spam comments?
    If so how do you stop it, any plugin or anything you can suggest?
    I get so much lately it’s driving me insane so any assistance is very much appreciated.

    Comment by methadone addiction — June 14, 2013 @ 2:14 am

  37. My brother suggested I may like this blog. He used to be entirely right.
    This publish actually made my day. You can not believe simply how much time I had spent
    for this info! Thanks!

    Comment by oddluzanie - odd_u_enie — June 22, 2013 @ 4:32 pm

  38. Hi there! I know this is kind of off-topic but I had to ask.

    Does managing a well-established blog such as yours take a lot of work?
    I am completely new to blogging but I do write in my journal everyday.

    I’d like to start a blog so I can share my experience and feelings online. Please let me know if you have any ideas or tips for brand new aspiring bloggers. Appreciate it!

    Comment by Louisville AC Repair — July 24, 2013 @ 12:40 am

  39. @Guven… thanks alot ..

    Comment by LinuxBee — August 13, 2013 @ 12:37 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Silver is the New Black Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: