如何在使用SBT& amp;的开发和生产中正确地管理logback配置.斯卡拉(Scala)? [英] How to properly manage logback configrations in development and production using SBT & Scala?
问题描述
我有一个非常漂亮的Scalatra项目,它使用Logback进行记录.
I have a pretty standard Scalatra project using Logback for logging.
在 logback手册之后,我为开发配置添加了logback-test.xml
(调试日志),同时保持生产logback.xml
.
Following the logback manual I have added a logback-test.xml
for my development configuration (logs of debugs), whilst maintaining a production logback.xml
.
但是,在开发中,使用xsbt-web-plugin
来运行容器并重新加载代码时,我的应用似乎只能使用logback.xml
.
However, in development while using the xsbt-web-plugin
to run a container with code reloading, my app only seems to pick up the logback.xml
.
如何获得所需的行为?:
How do I get the desired behavior?:
- 在开发模式(
./sbt container:start
)中,应用使用logback-test.xml
- 使用 SBT组装组装成zip时,请排除测试配置.
- In development mode (
./sbt container:start
) the app useslogback-test.xml
- When assembled into a zip using SBT-assembly, exclude the test config.
目前这些似乎都不起作用.
Currently neither of these seems to work.
推荐答案
您正在滥用logback-test.xml
.它仅适用于类单元测试,应放置在src/test/resources
中(该产品会自动从产品中排除).要实现您想要的目标-您可以通过系统属性设置logback-dev.xml
的路径:
You're misusing logback-test.xml
. It's intended for unit-like tests only and should be placed in src/test/resources
(which is automatically excluded from prod). To achieve what you want - you may set up path to your logback-dev.xml
by system property:
javaOptions in container += "-Dlogback.configurationFile=/some/path/logback-dev.xml"
此路径可能是相对的.参见 https://stackoverflow.com/a/26538449/1809978
This path may be relative. See, https://stackoverflow.com/a/26538449/1809978
在我的实践中,即使在产品(它指向某个外部位置)中,我们也不打包logback.xml
来具有临时更改日志记录配置的功能.
In my practice we don't pack logback.xml
even in prod (it's pointed to some external place) to have ability to change logging configuration ad-hoc.
P.S.如果您也有兴趣从sbt-assembly中排除文件-这可能会帮助
P.S. If you're also interested about excluding files from sbt-assembly - this may help
这篇关于如何在使用SBT& amp;的开发和生产中正确地管理logback配置.斯卡拉(Scala)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!