Springboot Log management + integrated log4j

Source: Internet
Author: User

The default logging framework used by Sprongboot is logback.

You can configure simple log properties in Application.properties, you can configure the Logback.xml format separately, and you can use log4j to manage it.

The following sections describe your own log configuration and how to use log4j for log management.

1. Your own log management configuration:

1.1 Modifying Application.properties

#配置日志logging. level.root=infologging.level.org.springframework.web=debuglogging.level.org.hibernate=error# Logging.path=d:\\demo1logging.file=d:\\springboot3\\log\\demo2.log

This simple and rude convenience

2. Using log4j Management

2.1 Modify the Pom.xml file, filter out the spring-boot-starter-logging, and add the spring-boot-starter-log4j dependency package.

    <!--log4j -    <Dependency>        <groupId>Org.springframework.boot</groupId>        <Artifactid>Spring-boot-starter</Artifactid>        <Exclusions>            <exclusion>                <groupId>Org.springframework.boot</groupId>                <Artifactid>Spring-boot-starter-logging</Artifactid>            </exclusion>        </Exclusions>     </Dependency>        <Dependency>        <groupId>Org.springframework.boot</groupId>        <Artifactid>spring-boot-starter-log4j</Artifactid>        <version>1.3.8.RELEASE</version>    </Dependency>

2.2 Create a new log4j.properties configuration file under the Resources directory

Configure info,error,console,debug four output formats.

Log4j.rootlogger=Info,error,console,debugLog4j.appender.console=org.apache.log4j.consoleappender log4j.appender.console.layout= Org.apache.log4j.PatternLayout log4j.appender.console.layout.conversionpattern=%d{yyyy-mm-dd-hh-mm} [%t] [%c] [%p] -%m%n log4j.logger.info=infolog4j.appender.info=     Org.apache.log4j.dailyrollingfileappenderlog4j.appender.info.layout=org.apache.log4j.patternlayout  LOG4J.APPENDER.INFO.LAYOUT.CONVERSIONPATTERN=%D{YYYY-MM-DD-HH-MM} [%t] [%c] [%p]-%m%n Log4j.appender.info.datepattern= '. ' Yyyy-mm-ddlog4j.appender.info.threshold = info Log4j.appender.info.append=true log4j.appender.info.file=d:// Springboot3/logs/api_services_info.loglog4j.logger.error=error log4j.appender.error=     Org.apache.log4j.dailyrollingfileappenderlog4j.appender.error.layout=org.apache.log4j.patternlayout  LOG4J.APPENDER.ERROR.LAYOUT.CONVERSIONPATTERN=%D{YYYY-MM-DD-HH-MM} [%t] [%c] [%p]-%m%n Log4j.appender.error.datepattern= '. ' Yyyy-mm-ddlog4j.appender.error.threshold = Error Log4j.appender.error.append=true  log4j.appender.error.file=d://springboot3/logs/error/api_services_error.loglog4j.logger.debug= debuglog4j.appender.debug=org.apache.log4j.dailyrollingfileappenderlog4j.appender.debug.layout= Org.apache.log4j.PatternLayout log4j.appender.debug.layout.conversionpattern=%d{yyyy-mm-dd-hh-mm} [%t] [%c] [%p]-% m%n log4j.appender.debug.datepattern= '. ' Yyyy-mm-ddlog4j.appender.debug.threshold = DEBUG Log4j.appender.debug.append=true log4j.appender.debug.file=d:// Springboot3/logs/debug/api_services_debug.log

3. Declare the log and output log information in the class used.

The output results are as follows:

Springboot Log management + integrated log4j

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.