第二步,将控制台的日志改成彩色日志,便于查看
修改logback.xml文件。
xml version&#61;"1.0" encoding&#61;"UTF-8"?><configuration debug&#61;"false"><contextName>testLogcontextName><conversionRule conversionWord&#61;"clr" converterClass&#61;"org.springframework.boot.logging.logback.ColorConverter" /><conversionRule conversionWord&#61;"wex" converterClass&#61;"org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" /><conversionRule conversionWord&#61;"wEx" converterClass&#61;"org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" /><property name&#61;"CONSOLE_LOG_PATTERN" value&#61;"${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/><appender name&#61;"STDOUT" class&#61;"ch.qos.logback.core.ConsoleAppender"><encoder><pattern>&#61;&#61;&#61;%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger Line:%-3L - %msg%npattern><Pattern>${CONSOLE_LOG_PATTERN}Pattern><charset>UTF-8charset>encoder>appender><root level&#61;"INFO"><appender-ref ref&#61;"STDOUT" />root>configuration>
控制台打印彩色日志的效果&#xff0c;如图所示&#xff1a;
到这里&#xff0c;就完成了控制台打印彩色日志。