Java 将 logback.xml 放在 Tomcat 的何处?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20427307/
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
Where to put logback.xml in Tomcat?
提问by Harold L. Brown
Where to put the logback.xmlfile in Tomcat when we want to have it configurable?
当我们想让它可配置时,将logback.xml文件放在 Tomcat 的什么位置?
And how to make it accessible for the Java application(s) running inside?
以及如何使其内部运行的 Java 应用程序可以访问它?
采纳答案by Sotirios Delimanolis
You typically want to have logback.xml
on the classpath. Per the Logback FAQ:
您通常希望logback.xml
在类路径上拥有。根据Logback 常见问题解答:
For web-applications, configuration files can be placed directly under WEB-INF/classes/.
对于 web 应用程序,配置文件可以直接放在 WEB-INF/classes/ 下。
You therefore need to put it in:
因此,您需要将其放入:
/webapps/your-app/WEB-INF/classes/
Logback has some conventions for where it looks for it. Those are documented here.
Logback 有一些关于它在哪里查找的约定。这些记录在此处。
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.
Logback 尝试在类路径中找到一个名为 logback.groovy 的文件。
如果没有找到这样的文件,logback 会尝试在类路径中找到一个名为 logback-test.xml 的文件。
如果没有找到这样的文件,它会检查类路径中的文件 logback.xml..
如果两个文件都没有找到,logback 会使用 BasicConfigurator 自动配置自己,这将导致日志输出被定向到控制台。
But you can also tell it where to find the file.
但是您也可以告诉它在哪里可以找到文件。
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.
您可以使用名为“logback.configurationFile”的系统属性指定默认配置文件的位置。此属性的值可以是 URL、类路径上的资源或应用程序外部文件的路径。
java -Dlogback.configurationFile=/path/to/config.xml chapters.configuration.MyApp1
请注意,文件扩展名必须是“.xml”或“.groovy”。其他扩展名将被忽略。显式注册状态侦听器可能有助于调试定位配置文件的问题。