问题描述
我正在尝试配置我的石英调度程序以支持日志记录.我曾尝试进行以下操作:
在我的应用程序的类文件夹中添加了log4j.xml.相同的代码是:
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
在我的调度程序类中添加了以下语句:
static Logger logger = Logger.getLogger("QuartzReport.class"); logger.info("Info");
但是,控制台以启动显示以下消息:
log4j:WARN No appenders could be found for logger (org.quartz.simpl.SimpleThreadPool). log4j:WARN Please initialize the log4j system properly.
请告诉我我是否缺少东西.
问候, ibu
推荐答案
您缺少两点:
- 您的配置文件是属性文件,而不是XML.因此,您应该将其保存为" log4j.properties";
- 确保项目1中提到的文件位于应用程序的类Path(假设正在使用最近的Log4J实现)中.
祝你好运,
道格拉斯
其他推荐答案
也尝试使用此行更新您的log4j配置
log4j.logger.org.quartz = debug,stdout
其他推荐答案
您可以通过编程进行编码(如QuartzReport类的主要方法),要么使用配置文件(您的属性文件).
log4j的较新版本将尝试从class路径加载一个名为log4j.properties的文件,并使用它自动配置logger.
在您的情况下,BasicConfigurator.configure()呼叫将覆盖您属性文件中的任何定义(即,您的属性文件被忽略).日志显示的输出尊重您在PatternLayout构造函数中提供的模式.有关如何定义此类模式的更多详细信息,请参见 PatternLayout类文档.
问题描述
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.