Engineering Full Stack Apps with Java and JavaScript
Spring Boot has no mandatory logging dependency, except for the Commons Logging API, of which there are many implementations to choose from.
Spring Boot attempts to configure logging based on the content of the classpath if you use spring-boot-starter-logging. 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.
If Logback is available, it is the first choice of logging configuration for Spring. Provided we are using spring-boot-starter-logging directly or indirectly. To use Logback, you need to include it and jcl-over-slf4j on the classpath.
You can override default log levels 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 instead of console-appender.xml.
Spring Boot supports Log4j 2 for logging configuration if it is on the classpath. I
f 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.