Logback configuration via jvm argument

2019-06-14 23:07发布

How can we load logback.xml via jvm argument if this is not present in project classpath?

I'm using

 -Dlogback.configuration=file:C:\logbacs\logback.xml 

but this is not working.

3条回答
祖国的老花朵
2楼-- · 2019-06-14 23:15

If you're not using SpringBoot the above won't work.

I'm using the ch.qos.logback.logback-classic library, and in this case the solution is

-Dlogback.configurationFile=file:/app/logback.xml

I've found this property in ch.qos.logback.classic.util.ContextInitializer:

final public static String CONFIG_FILE_PROPERTY = "logback.configurationFile"
查看更多
太酷不给撩
3楼-- · 2019-06-14 23:21

The original answer to this question doesn't appear to be working anymore as it produces this warning instead:

o.s.b.l.logback.LogbackLoggingSystem     : Ignoring 'logback.configurationFile' system property. Please use 'logging.config' instead.

Therefore, you would want to use something like this:

-Dlogging.config="C:\logbacs\logback.xml"
查看更多
劫难
4楼-- · 2019-06-14 23:31

I found the solution

-Dlogging.config="C:\logbacs\logback.xml"

is working fine for me.

Updated because the previous answer was obsolete

查看更多
登录 后发表回答