java Quartz 调度程序不显示 Log4j 消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/725228/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 13:30:39  来源:igfitidea点击:

Quartz scheduler not displaying Log4j messages

javalogginglog4jquartz-scheduler

提问by

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

我正在尝试配置我的 Quartz 调度程序以支持日志记录。我曾尝试执行以下操作:

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

在我的应用程序的类文件夹中添加了 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

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

问候,伊布

回答by Douglas

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).
  1. 您的配置文件是一个属性文件,而不是 XML。所以你应该把它保存为“log4j.properties”;
  2. 确保第 1 项中提到的文件位于应用程序的类路径中(假设正在使用最近的 log4j 实现)。

Good luck,

祝你好运,

Douglas

道格拉斯

回答by user88193

Also try updating your log4j config with this line

还尝试使用此行更新您的 log4j 配置

log4j.logger.org.quartz=debug, stdout

log4j.logger.org.quartz=调试,标准输出

回答by Douglas

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

您可以QuartzReport使用配置文件(您的属性文件)以编程方式(如在您的类的主要方法中)配置您的代码。

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

较新版本的 Log4j 将尝试加载一个以log4j.properties您的类路径命名的文件,并使用它来自动配置您的记录器。

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 PatternLayoutconstructor. More details on how to define such pattern can be found in the PatternLayoutclass documentation.

在您的情况下,BasicConfigurator.configure()调用将覆盖您的属性文件中的任何定义(即,您的属性文件被忽略)。日志显示的输出尊重您在PatternLayout构造函数中提供的模式。有关如何定义此类模式的更多详细信息,请参见PatternLayout类文档