gpt4 book ai didi

xml - : logback. xml 和 logback-test.xml 哪个优先?

转载 作者:数据小太阳 更新时间:2023-10-29 01:46:35 27 4
gpt4 key购买 nike

我对 logback 很陌生。如果我的 spring boot 项目包含这两个文件 -

  • logback.xml:存在于*src/main/resources/下
  • logback-test.xml:存在于*src/test/resources/下

哪个会加载? logback.xml 还是 logback-test.xml

我正在阅读 logback 的文档,它说,首先它会查找 logback-test.xml,然后是 logback.xml

那么如果我们部署应用程序,logback-test.xml 文件是否会优先于 logback.xml

谢谢!

苏拉布

最佳答案

来自 the docs :

Let us begin by discussing the initialization steps that logback follows to try to configure itself:

  1. Logback tries to find a file called logback-test.xml in the classpath.

  2. If no such file is found, logback tries to find a file called logback.groovy in the classpath.

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

  4. If no such file is found, service-provider loading facility (introduced in JDK 1.6) is used to resolve the implementation of com.qos.logback.classic.spi.Configurator interface by looking up the file META-INF\services\ch.qos.logback.classic.spi.Configurator in the class path. Its contents should specify the fully qualified class name of the desired Configurator implementation.

  5. If none of the above succeeds, logback configures itself automatically using the BasicConfigurator which will cause logging output to be directed to the console.

The last step is meant as last-ditch effort to provide a default (but very basic) logging functionality in the absence of a configuration file.

所以,这个问题的答案...

Which takes priority: logback.xml or logback-test.xml?

...是logback-test.xml

但是,这个问题...

So is it like logback-test.xml file will take a priority over logback.xml if we deploy the application?

... 使事情稍微复杂化。如果您部署 logback-test.xmllogback.xml 然后 logback-test.xml 将优先但是部署logback-test.xml并不常见。实际上,鉴于您的问题中提供的位置 logback-test.xml 默认情况下不会部署,因为它位于测试树中 (src/test/resources) .

同样,来自 the docs :

If you are using Maven and if you place the logback-test.xml under the src/test/resources folder, Maven will ensure that it won't be included in the artifact produced. Thus, you can use a different configuration file, namely logback-test.xml during testing, and another file, namely, logback.xml, in production.

所以,总结一下;默认情况下 logback-test.xml 不会被部署,因此 logback.xml 将在您部署的系统中使用,但 logback-test.xml 将运行测试用例时优先于 logback.xml

关于xml - : logback. xml 和 logback-test.xml 哪个优先?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50560184/

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