在哪里将logback.xml放在Tomcat中? [英] Where to put logback.xml in Tomcat?

查看:1986
本文介绍了在哪里将logback.xml放在Tomcat中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们想要将其配置时,在Tomcat中放置 logback.xml 文件的位置?

Where to put the logback.xml file in Tomcat when we want to have it configurable?


And how to make it accessible for the Java application(s) running inside?

推荐答案

您通常希望拥有 logback.xml code>在类路径。根据退回常见问题

You typically want to have logback.xml on the classpath. Per the Logback FAQ:

对于Web应用程序,配置文件可以直接放在WEB-INF / classes /下。

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

因此您需要将其放入:

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

Logback对它查找的位置有一些约定。 这些文档在此处

Logback has some conventions for where it looks for it. Those are documented here.


  • Logback会尝试在类路径中找到名为logback.groovy的档案。

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

如果没有找到这样的文件,logback尝试在类路径中找到一个名为logback-test.xml的文件。

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

如果找不到这两个文件,logback会使用BasicConfigurator自动配置自身,这会导致日志输出
指向控制台。

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


您可以使用名为logback的
系统属性指定默认配置文件的位置。 configurationFile。此
属性的值可以是URL,类路径上的资源或应用程序外部的
文件的路径。

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

请注意,文件扩展名必须是.xml或.groovy。其他
扩展被忽略。显式注册状态监听器可以
帮助调试找到配置文件的问题。

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.xml放在Tomcat中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆