Arvind Katte
Arvind Katte

Reputation: 1003

How to load logback.xml file from external path, other than resource folder

I'm not able to print the slf4j log message. The controller is not loading logback.xml file. I searched on net I found that

static 
{ 
    System.setProperty("logback.configurationFile",     "D:/RxBDataFeeder/RxBDataFeeder/config/logback.xml");
}

This code is also not working.

Upvotes: 1

Views: 9976

Answers (3)

canne
canne

Reputation: 58

This will fix:

$javapath -jar $jarname --logging.config=/path/to/logback.xml

Upvotes: 0

J-J
J-J

Reputation: 5871

you can pass the logback config file as a param while starting the app as shown below.

java -Dlogback.configurationFile=path/logback.xml MyApp

if you want to automatically reconfigure it when you change something it your logback.xml then use the below in logback.xml

<configuration scan="true" scanPeriod="30 seconds" > 
  ...
</configuration> 

Upvotes: 3

Antoniossss
Antoniossss

Reputation: 32535

logback.xml is ment to be loaded from external resources as a standalone file, so sysadmin can change logging settings without recompiling the code.

LoggerFactory automaticly picks up any logback.xml file from the classpath, so in order to use external file, add its containing directory to a runtime classpath.

How to set runtime classpath is described here https://docs.oracle.com/javase/tutorial/essential/environment/paths.html

Upvotes: 1

Related Questions