1

I get the following:

log4j:WARN No appenders could be found for logger (org.test.Books).  
log4j:WARN Please initialize the log4j system properly.

I do not want to print these messages, regardless to whether if my log4j configuration is correct or not.

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
Yair Zaslavsky
  • 4,091
  • 4
  • 20
  • 27

1 Answers1

1

To turn off the warnings try:

Logger.getRootLogger().setLevel(Level.OFF);

And as said in the comment it might be better using the log4j.xml here is a nice link on its format and a few examples too: http://wiki.apache.org/logging-log4j/Log4jXmlFormat

Reference:

Community
  • 1
  • 1
David Kroukamp
  • 36,155
  • 13
  • 81
  • 138
  • 2
    +1, but I'd recommend to do this using `log4j.xml` configuration file. – AlexR Jul 29 '12 at 13:29
  • @AlexR Thank you added link to the log4j.xml format which also has a few examples and nice explanations – David Kroukamp Jul 29 '12 at 13:35
  • What I tried at first is to use -Dlog4j.configuration=file:. I did manage to use log4j, but I still saw these warnings, so I asked this question. Does anyone have a clue why it acts like this? – Yair Zaslavsky Jul 29 '12 at 19:37
  • @zaske Maybe see here: http://stackoverflow.com/questions/7685510/log4j-warning-while-initializing and http://activemq.apache.org/log4j-warn-no-appenders-could-be-found-for-logger.html – David Kroukamp Jul 29 '12 at 19:41