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

标签 java tomcat logging configuration logback

当我们想要配置 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/

相关文章:

java - 线程间通信

java - Gradle Error URI 有一个权限组件

java - 使用 Http11NioProtocol 在 Tomcat SSL 中启用 SSL

未找到 JSP 类异常

testing - 登录自动化测试

Python记录到日志文件的头部?

java - Hazelcast内部共享f分布式 map

url - Tomcat对URL中的中文进行加密,如何取消?

Python TimedRotatingFileHandler 旋转是如何发生的

java - 使用 Bindy 解析数据时出现日期模式问题