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
You're missing essentialy two points:
- Your configuration file is a properties file, not an XML. So you should save it as 'log4j.properties';
- 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
Also try updating your log4j config with this line
log4j.logger.org.quartz=debug, stdout
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