SpringBoot3-日志
Springboot和日志
考虑和jdbc和数据库驱动一样,我们抽象出一个日志的接口 ## 常见的java日志 JUL,JCL,JBoss-logging,logback,log4j,log4j2,slf4j ### Java抽象 JCL,SLF4j,Jboss-logging ### Java实现 Log4j,JUL,Log4j2,logback ### 怎么选择 选择SLF4j+Logback ### SpringBoot怎么搞? Spring选择了JUL,SpringBoot选择了SLF4j+Logback ## SLF4j使用 调用日志抽象层的方法,而不是实现 1
2Logger logger = LoggerFactory.getLogger(?.class);
logger.info("hello world")1
2
3
4
5
6spring-boot-starter-logging
logback-classic
3个狸猫包偷梁换柱
jul-to-slf4j
log4j-ober-slf4j
jcl-ober-slf4j1
2
3logging.level.com.wsx.springboothelloworld = debug
logging.path= log
logging.pattern.console=%d{yyyy-MM-dd:HH:mm:ss.SSS} [%thread] %-5level %logger{50} -%msg%n1
2
3
4
5
6
7
8
9
10
void contextLoads() {
// System.out.println(person);
Logger logger = LoggerFactory.getLogger(getClass());
logger.error("hi");
logger.warn("hi");
logger.info("info hi");
logger.debug("debug hi");
logger.trace("trace hi");
}