log4j2.xml 文件在 tomcat 网络应用程序中的正确位置

Proper location of log4j2.xml files within a tomcat webapp

我们有一个包含两个 log4j2.xml 文件的网络应用程序:

我的问题是:

  1. tomcat 如何读取和评估这些文件?
  2. 阅读顺序是什么?
  3. 是否可以用 (1) 覆盖 (2) 的设置,我该怎么做?

谢谢。

阅读文档here您会发现:

Log4j allows the configuration file to be specified in web.xml using the log4jConfiguration context parameter. Log4j will search for configuration files by:

  1. If a location is provided it will be searched for as a servlet context resource. For example, if log4jConfiguration contains "logging.xml" then Log4j will look for a file with that name in the root directory of the web application.
  2. If no location is defined Log4j will search for a file that starts with "log4j2" in the WEB-INF directory. If more than one file is found, and if a file that starts with "log4j2-name" is present, where name is the name of the web application, then it will be used. Otherwise the first file will be used.
  3. The "normal" search sequence using the classpath and file URLs will be used to locate the configuration file.

如果我没理解错的话,这就回答了你所有的问题。