Springboot日志初探
2021-01-03 10:27
标签:coder system boot from you factory mba ons iter pom.xml log4j2.xml Springboot日志初探 标签:coder system boot from you factory mba ons iter 原文地址:https://www.cnblogs.com/zhaoran8775/p/12990758.html1.新建module,springboot-log
2.pom.xml
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
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.切换日志实现