log4j2.xml 文件在 tomcat 网络应用程序中的正确位置
Proper location of log4j2.xml files within a tomcat webapp
我们有一个包含两个 log4j2.xml
文件的网络应用程序:
WEB-INF/classes
中的一个包含特定于 webapp 的日志记录设置(1),以及
- 一个在位于
WEB-INF/lib
的依赖项的根目录中,其中包含我们也在其他 Web 应用程序中使用的默认日志记录设置 (2)
我的问题是:
- tomcat 如何读取和评估这些文件?
- 阅读顺序是什么?
- 是否可以用 (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:
- 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.
- 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.
- The "normal" search sequence using the classpath and file URLs will be used to locate the configuration file.
如果我没理解错的话,这就回答了你所有的问题。
我们有一个包含两个 log4j2.xml
文件的网络应用程序:
WEB-INF/classes
中的一个包含特定于 webapp 的日志记录设置(1),以及- 一个在位于
WEB-INF/lib
的依赖项的根目录中,其中包含我们也在其他 Web 应用程序中使用的默认日志记录设置 (2)
我的问题是:
- tomcat 如何读取和评估这些文件?
- 阅读顺序是什么?
- 是否可以用 (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:
- 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.
- 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.
- The "normal" search sequence using the classpath and file URLs will be used to locate the configuration file.
如果我没理解错的话,这就回答了你所有的问题。