Quartz scheduler not displaying Log4j messages

£可爱£侵袭症+ 提交于 2019-12-07 13:14:12

问题


I am trying to configure my Quartz scheduler to support logging. I had tried doing following:

Added log4j.xml in classes folder of my app. The code for the same is:

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=
    %d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.rootLogger=debug, stdout

Added following statements in my scheduler class:

static Logger logger = Logger.getLogger("QuartzReport.class");
logger.info("Info");

However, the console displays the following message with start up:

log4j:WARN No appenders could be found for logger 
    (org.quartz.simpl.SimpleThreadPool).
log4j:WARN Please initialize the log4j system properly.

Please tell me whether I am missing somthing.

Regards, Ibu


回答1:


You're missing essentialy two points:

  1. Your configuration file is a properties file, not an XML. So you should save it as 'log4j.properties';
  2. Make sure the file mentioned in the item 1 is in the application's classpath (assuming a recent log4j implementation is being used).

Good luck,

Douglas




回答2:


Also try updating your log4j config with this line

log4j.logger.org.quartz=debug, stdout




回答3:


You can configure you code either programatically (as in the main method of your QuartzReport class), either with a configuration file (your properties file).

Newer versions of Log4j will try to load a file named log4j.properties from you classpath and use it to configure you logger automatically.

In your case, the BasicConfigurator.configure() call will override any definitions in you properties file (i.e., you properties file is being ignored). And the output displayed by the log respects the pattern you provided in the PatternLayout constructor. More details on how to define such pattern can be found in the PatternLayout class documentation.



来源:https://stackoverflow.com/questions/725228/quartz-scheduler-not-displaying-log4j-messages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!