Springboot日志初探

2021-01-03 10:27

阅读:421

标签:coder   system   boot   from   you   factory   mba   ons   iter   

1.新建module,springboot-log

2.pom.xml

4.0.0org.springframework.boot
        spring-boot-starter-parent
        2.3.0.RELEASEcom.lxcourse
    springboot-log
    0.0.1-SNAPSHOTspringboot-logDemo project for Spring Boot1.8org.springframework.boot
            spring-boot-starter-web
        org.springframework.boot
            spring-boot-starter-test
            testorg.junit.vintage
                    junit-vintage-engine
                org.springframework.boot
                spring-boot-maven-plugin
            

3.application.properties

logging.pattern.console=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} %thread %c %M ---- %msg%n 
logging.level.com.lxcourse=trace
logging.file.path=/Users/doubledumbao/logs/springboot-log
logging.pattern.file=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} %thread %c %M ---- %msg%n 
spring.profiles.active=dev

4.logback-spring.xml

System.err[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} %C %M [%thread]------- %msg%n[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} %C %M [%thread] xxxxxxxx %msg%n

5.测试类

package com.lxcourse.springbootlog;

import org.apache.logging.log4j.LogManager;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class SpringbootLogApplicationTests {

    public static final Logger LOGGER = LoggerFactory.getLogger(SpringbootLogApplication.class);

    @Test
    public void testQuick(){
        LOGGER.error("error");
        LOGGER.warn("warn");
        LOGGER.info("info");
        LOGGER.debug("debug");
        LOGGER.trace("trace");

        org.apache.logging.log4j.Logger logger = LogManager.getLogger(SpringbootLogApplication.class);
        logger.info("log4j2 log");
    }

}

6.切换日志实现

pom.xml

4.0.0org.springframework.boot
        spring-boot-starter-parent
        2.3.0.RELEASEcom.lxcourse
    springboot-log
    0.0.1-SNAPSHOTspringboot-logDemo project for Spring Boot1.8org.springframework.boot
            spring-boot-starter-web
            
            
                    spring-boot-starter-logging
                    org.springframework.bootorg.springframework.boot
            spring-boot-starter-log4j2
        org.springframework.boot
            spring-boot-starter-test
            testorg.junit.vintage
                    junit-vintage-engine
                org.springframework.boot
                spring-boot-maven-plugin
            

log4j2.xml

/Users/doubledumbao/logs/logger

Springboot日志初探

标签:coder   system   boot   from   you   factory   mba   ons   iter   

原文地址:https://www.cnblogs.com/zhaoran8775/p/12990758.html


评论


亲,登录后才可以留言!