Where to put logback.xml in Tomcat?

Harold L. Brown picture Harold L. Brown · Dec 6, 2013 · Viewed 23.3k times · Source

Where to put the logback.xml file in Tomcat when we want to have it configurable?

And how to make it accessible for the Java application(s) running inside?

Answer

Sotirios Delimanolis picture Sotirios Delimanolis · Dec 6, 2013

You typically want to have logback.xml on the classpath. Per the Logback FAQ:

For web-applications, configuration files can be placed directly under WEB-INF/classes/.

You therefore need to put it in:

/webapps/your-app/WEB-INF/classes/

Logback has some conventions for where it looks for it. Those are documented here.

  • Logback tries to find a file called logback.groovy in the classpath.

  • If no such file is found, logback tries to find a file called logback-test.xml in the classpath.

  • If no such file is found, it checks for the file logback.xml in the classpath..

  • If neither file is found, logback configures itself automatically using the BasicConfigurator which will cause logging output to be directed to the console.

But you can also tell it where to find the file.

You may specify the location of the default configuration file with a system property named "logback.configurationFile". The value of this property can be a URL, a resource on the class path or a path to a file external to the application.

java -Dlogback.configurationFile=/path/to/config.xml chapters.configuration.MyApp1

Note that the file extension must be ".xml" or ".groovy". Other extensions are ignored. Explicitly registering a status listener may help debugging issues locating the configuration file.