gpt4 book ai didi

java - 将 logback.xml 放在 Tomcat 的什么位置?

转载 作者:IT老高 更新时间:2023-10-28 20:34:08 25 4
gpt4 key购买 nike

当我们想要配置 logback.xml 文件在 Tomcat 中的什么位置?

以及如何使其内部运行的 Java 应用程序可以访问它?

最佳答案

您通常希望在类路径中包含 logback.xml。根据 Logback FAQ :

For web-applications, configuration files can be placed directly under WEB-INF/classes/.

因此您需要将其放入:

/webapps/your-app/WEB-INF/classes/

Logback 有一些关于它在哪里寻找它的约定。 Those are documented here .

  • Logback tries to find a file called logback.groovy in the classpath.

  • If no such file is found, logback tries to find a file called logback-test.xml in the classpath.

  • If no such file is found, it checks for the file logback.xml in the classpath..

  • If neither file is found, logback configures itself automatically using the BasicConfigurator which will cause logging output to be directed to the console.

但你也可以告诉它在哪里可以找到文件。

You may specify the location of the default configuration file with a system property named "logback.configurationFile". The value of this property can be a URL, a resource on the class path or a path to a file external to the application.

java -Dlogback.configurationFile=/path/to/config.xml chapters.configuration.MyApp1

Note that the file extension must be ".xml" or ".groovy". Other extensions are ignored. Explicitly registering a status listener may help debugging issues locating the configuration file.

关于java - 将 logback.xml 放在 Tomcat 的什么位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20427307/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com