30

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.

Sai prateek
  • 11,842
  • 9
  • 51
  • 66

5 Answers5

44

I found the solution

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

is working fine for me.

Updated because the previous answer was obsolete

Andras Szell
  • 527
  • 2
  • 13
Sai prateek
  • 11,842
  • 9
  • 51
  • 66
23

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"
Rudi
  • 419
  • 6
  • 10
  • 1
    This definitely not correct anymore in recent versions of spring boot. It's `-Dlogging.config`, see answer by @Fre_d – jaw Aug 14 '18 at 12:08
  • 3
    like I've said, I've used -Dlogback.configurationFile property because I wasn't using spring boot. If you use SB, then you should use -Dlogging.config – Rudi Aug 15 '18 at 07:32
  • Not necessary to explore Logback's source code, using this property is explained here : http://logback.qos.ch/manual/configuration.html#configFileProperty – jdarthenay Jan 06 '21 at 13:44
  • For Windows -Dlogback.configurationFile=file:///C:/logbacs/logback.xml – JustinKSU Jun 07 '21 at 21:15
5

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"
Freya
  • 302
  • 5
  • 10
0

For me it works only with this property:

-Dconfig.dir= "YOUR PATH TO CONFIG FILE"
0

As per https://logback.qos.ch/manual/configuration.html, use -Dlogback.configurationFile

java -Dlogback.configurationFile=/path/to/config.xml chapters.configuration.MyApp1
Vimal Bhatt
  • 71
  • 1
  • 3