Logging with Spring Boot

Spring Boot has no mandatory logging dependency, except for the Commons Logging API, of which there are many implementations to choose from.


Using Logback

To use Logback, you need to include it and jcl-over-slf4j on the classpath, and this is added automatically if you use spring-boot-starter-logging. Spring Boot attempts to configure logging based on the content of the classpath. If Logback is available, it is the first choice.

Most other starters such as spring-boot-starter-web depends transitively on the logging starter, and hence it is automatically added if they are being used. The only change you may need to make to logging is to set the levels of various loggers then you can do that in application.properties using the "logging.level" prefix, e.g. logging.level.org.springframework.web=DEBUG.

If you put a logback.xml in the root of your classpath it will be picked up from there (or logback-spring.xml to take advantage of the templating features provided by Boot). Spring Boot provides a default base configuration (base.xml will be present in the spring-boot jar) that you can include if you just want to set levels. If you want to disable console logging and write output only to a file you need a custom logback-spring.xml that imports file-appender.xml but not console-appender.xml.


Using Log4j

Spring Boot supports Log4j 2 for logging configuration if it is on the classpath. If you are using the starters for assembling dependencies that means you have to exclude Logback and then include log4j 2 instead. If you aren’t using the starters then you need to provide jcl-over-slf4j (at least) in addition to Log4j 2.

In addition to its default XML configuration format, Log4j 2 also supports YAML and JSON configuration files. To configure Log4j 2 to use an alternative configuration file format, add the appropriate dependencies to the classpath and name your configuration files to match your chosen file format.


Ream more @ http://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html.

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!