简体   繁体   English

如果没有找到配置文件,log4j2会发出警告吗?

[英]Does log4j2 warn if no configuration file is found?

I have no log4j2 configuration files defined in my classpath. 我的classpath中没有定义log4j2配置文件。 My log messages are still going to the console and I see no warning about a missing configuration. 我的日志消息仍然会进入控制台,我看不到有关丢失配置的警告。

I am running a servlet based application on Tomcat 7. 我在Tomcat 7上运行基于servlet的应用程序。

I'm trying to figure out how it is getting this configuration? 我想弄清楚它是如何获得这种配置的?

I am expecting to see the warning in log4j2 like you would see in log4j. 我希望在log4j2中看到警告,就像你在log4j中看到的那样。

Log4j2 can autoconfigure itself if you do not provide a config file. 如果您不提供配置文件,Log4j2可以自动配置。

Configuration of Log4j 2 can be accomplished in 1 of 4 ways: Log4j 2的配置可以通过以下四种方式之一完成:

  1. Through a configuration file written in XML or JSON. 通过用XML或JSON编写的配置文件。
  2. Programmatically, by creating a ConfigurationFactory and Configuration implementation. 以编程方式,通过创建ConfigurationFactory和Configuration实现。
  3. Programmatically, by calling the APIs exposed in the Configuration interface to add components to the default configuration. 以编程方式,通过调用Configuration接口中公开的API将组件添加到默认配置。
  4. Programmatically, by calling methods on the internal Logger class. 以编程方式,通过调用内部Logger类上的方法。

http://logging.apache.org/log4j/2.x/manual/configuration.html#AutomaticConfiguration http://logging.apache.org/log4j/2.x/manual/configuration.html#AutomaticConfiguration

I am using Tomcat. 我正在使用Tomcat。 When I removed the log4j2.xml file This is the message that I see when the web server starts: 当我删除log4j2.xml文件时这是我在Web服务器启动时看到的消息:

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.

Since the severity is ERROR, the message is indeed quite visibile. 由于严重性为ERROR,因此该消息确实非常可见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM