本文介绍了为什么以不同的顺序加载回发配置并忽略系统属性(SBT)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试解决我的日志记录情况(),我遇到了一个有趣的问题.

I've been trying to sort out my logging situation (How to properly manage logback configrations in development and production using SBT & Scala?), and I've run across a funny problem.

根据 logback文档,logback检查,然后再检查logback.xml.

According to the logback documentation, logback checks for logback-test.xml before it checks for logback.xml.

我有以下文件:

  • src/main/resources/logback.xml
  • src/test/resources/logback-test.xml
  • src/main/resources/logback.xml
  • src/test/resources/logback-test.xml

所以我认为在运行sbt test时,它将查找logback-test.xml.在intellij(它本身管理测试执行)中确实如此,但是从命令行运行时似乎并非如此.

So I figured that when running sbt test, it would look to the logback-test.xml. This is true in intellij (which manages test execution itself), but does not seem to be true when running from the command line.

我重命名了logback.xml并打开了logback调试,这是输出.显然,它以相反的顺序查找文件:

I renamed my logback.xml and turned on logback debugging, and here is the output. Clearly it's looking for the files in the reverse order:

14:58:21,203 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [/home/rathboma/Projects/personal/beekeeper/src/main/resources/logback.xml]
14:58:21,206 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
14:58:21,206 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback-test.xml] at [file:/home/rathboma/Projects/personal/beekeeper/target/scala-2.10/test-classes/logback-test.xml]

我推测这是因为测试资源位于test-classes目录中,但我不知道如何正确解决此问题.

I'm speculating that it's because the test resources are in the test-classes directory, but I have no idea how to properly fix this.

其次,提供-Dlogback.configurationFile=config/logback-#{environment}.xml似乎什么也没做,它完全忽略了它.

SECONDLY, supplying -Dlogback.configurationFile=config/logback-#{environment}.xml doesn't seem to do anything, it toally ignores it.

有什么想法吗?

推荐答案

我假设您没有任何错别字,因为它与intellij兼容.

I am assuming you don't have any typos as it works with intellij.

Logback将尝试加载logback-test.xml,然后加载groovy,然后再加载普通的,请参见.通过尝试加载,我的意思是它将使类加载器进入正在运行的类(应该是测试类),并在资源中查找它.检查(例如,通过打印)资源的路径,并确认xml文件在那里. sbt默认情况下应确保在测试执行期间您的测试资源可用(请参见此处).如果您更改了构建sbt的非托管资源或测试任务依赖项,则可能无法复制.

Logback will try to load logback-test.xml then the groovy one then the normal one see this. By try to load I mean it will get the class loader to the class running (should be the test class) and look for it in the resources. Check (by print for example) the path to your resources and verify the xml file is there. sbt by default should make sure your test resources are available during test execution (see here). If you changed your build sbt's unmanaged resources or test task dependencies it might no get copied.

最后,如果您仍然没有找到问题(这很奇怪),我相信您应该启动一个干净的项目以检查问题是否仍然存在,否则,您应该清理intellij中的缓存.仍然看到问题吗?抱歉不能帮忙,也许您的sbt安装或版本有问题?

Finally if you still did not find the problem (which would be weird) I believe you should start a clean project to check if the problem persists, if it doesnt you should clean your cache in intellij. Still see a problem? sorry can't help, maybe a problem with your sbt installation or version?

祝你好运

这篇关于为什么以不同的顺序加载回发配置并忽略系统属性(SBT)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 20:07