Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put logback.xml in Tomcat?

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?

like image 262
Harold L. Brown Avatar asked Dec 06 '13 15:12

Harold L. Brown


People also ask

Where is Logback xml for Tomcat?

Particularly, setenv. bat and setenv.sh files are created in the tomcat/bin subfolder, and logback. xml is created in the tomcat/conf subfolder.

Where should Logback xml be stored?

In a Spring Boot application, you can put the Logback. xml file in the resources folder. If your Logback. xml file is outside the classpath, you need to point to its location using the Logback.

Where is Logback Spring xml?

xml or logback-spring. xml file under the src/main/resources folder. The configuration in XML file will override the logging properties in the application.

Does Tomcat use slf4j?

To allow web applications to use their own slf4j-api and logback-classic, classes used by Tomcat (particularly jcl-over-slf4j) must go into different, non-standard packages. According to Tomcat Documentation web application looks up classes in their WEB-INF/classes directory and WEB-INF/lib/*.


1 Answers

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.

like image 65
Sotirios Delimanolis Avatar answered Oct 04 '22 18:10

Sotirios Delimanolis