How to properly manage logback configrations in development and production using SBT & Scala?

孤人 提交于 2019-12-08 21:40:28

问题


I have a pretty standard Scalatra project using Logback for logging.

Following the logback manual I have added a logback-test.xml for my development configuration (logs of debugs), whilst maintaining a production 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?:

  1. In development mode (./sbt container:start) the app uses logback-test.xml
  2. When assembled into a zip using SBT-assembly, exclude the test config.

Currently neither of these seems to work.


回答1:


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"

This path may be relative. See, https://stackoverflow.com/a/26538449/1809978

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. If you're also interested about excluding files from sbt-assembly - this may help



来源:https://stackoverflow.com/questions/27538717/how-to-properly-manage-logback-configrations-in-development-and-production-using

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!