Spring Boot Learning (log configuration)

Source: Internet
Author: User
Tags java util

Support Log framework: Java Util Logging, log4j2 and Logback, using Logback by default
How to configure: Default profile configuration and reference external configuration file configuration

First, the default configuration file configuration (not recommended: not flexible, log4j2, etc. is not friendly)
# log file name, for example: Roncoo.log, or/var/log/roncoo.log
Logging.file=roncoo.log
# Log level configuration, for example: Logging.level.org.springframework=debug
Logging.level.*=info
Logging.level.org.springframework=debug

Second, reference external configuration file
2.1logback Configuration method:
Spring boot will load Classpath:logback-spring.xml or Classpath:logback-spring.groovy by default

Use a custom configuration file, configured as follows:
Logging.config=classpath:logback-roncoo.xml
Note: Do not use Logback to name this, otherwise spring boot will not be fully instantiated

1. Using spring boot-based configuration
<?xml version= "1.0" encoding= "UTF-8"?>
<configuration>
<include resource= "Org/springframework/boot/logging/logback/base.xml"/>
<logger name= "Org.springframework.web" level= "DEBUG"/>
</configuration>

2. Custom Configuration
See nearby

2.2LOG4J Configuration
2.2.1 Remove Logback Dependency package, add log4j2 dependency Package
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>

<!--using Log4j2--
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
2.2.2 Add Log4j2.xml or Log4j2-spring.xml in classpath (Spring boot default load)
2.3 Custom configuration Files
See annex

Three Comparison
Performance comparison: Log4j2 and Logback are better than log4j (deprecated)
Configuration: Logback The most concise, spring boot default, recommended to use

Example code:

Spring Boot Learning (log configuration)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.