Spring Boot???????????
????????? ???????[ 2017/5/18 10:08:57 ] ???????????ù??? Java ???
????spring Boot?????????????????Commons Logging????????????????????????????????磺Java Util Logging??Log4J??Log4J2??Logback?????Logger??????????????????????????????????????
????????????
??????Spring Boot???????????ERROR??WARN??INFO????????????????????
?????????????????????л???DEBUG????
????a.??????????????--debug??????磺$ Java -jar myapp.jar --debug
????b.??application.properties??????debug=true???????????true?????????Logger????????????????hibernate??spring??????????????????????????????????????????DEBUG????
??????????
????????????????ANSI?????ò??????????????????????????application.properties??????spring.output.ansi.enabled??????????
????a.NEVER??????ANSI-colored??????????
????b.DETECT???????????????ANSI?????????ò????????????
????c.ALWAYS?????????ANSI-colored????????????????????????к??????????????????
??????????
????Spring Boot????????????????????????????????????У??????????????????????????????????????????
????????????????????????application.properties??????logging.file??logging.path?????
????logging.file?????????????????·??????????????·?????磺logging.file=my.log
????logging.path??????????????????′???spring.log???????д???????????磺logging.path=/var/log
??????????????10Mb??С??????????????μ??????????????????ERROR??WARN??INFO
???????????
??????Spring Boot????????application.properties?н?????????????????????????
????????????logging.level.*=LEVEL
????logging.level????????????????*???????Logger??
????LEVEL?????TRACE?? DEBUG?? INFO?? WARN?? ERROR?? FATAL?? OFF
??????????
????logging.level.com.didispace=DEBUG??com.didispace????????class??DEBUG???????
????logging.level.root=WARN??root?????WARN???????
????????????????
????????????????????ApplicationContext???????????????????????????Spring???????????????????????????????Spring Boot??????????????????????????????????
????????????????????????????1????????????????????????????
????1.Logback??logback-spring.xml?? logback-spring.groovy?? logback.xml?? logback.groovy
????2.Log4j??log4j-spring.properties?? log4j-spring.xml?? log4j.properties?? log4j.xml
????3.Log4j2??log4j2-spring.xml?? log4j2.xml
????4.JDK (Java Util Logging)??logging.properties
????Spring Boot????????????????-spring??????????????????????????logback-spring.xml????????logback.xml??
???????????????
??????Spring Boot?п????????application.properties???????2???????????????
????logging.pattern.console????????????????????????????JDK Logger??
????logging.pattern.file??????????????????????????JDK Logger??
???????log4j??????
????????log4j????
?????????Spring Boot?????????????????spring-boot-starter?????а?????spring-boot-starter-logging??????????????Spring Boot??????????Logback????????????????log4j?????????????e???????????????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>
</dependency>
????????log4j.properties
????????????log4j?????????????src/main/resources???????log4j.properties??????????????????????????????????á?
????????????
?????????????????趨root?????????????INFO??appender?????????stdout:
????# LOG4J????
????log4j.rootCategory=INFO?? stdout
????# ????????
????log4j.appender.stdout=org.apache.log4j.ConsoleAppender
????log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
????log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss??SSS} %5p %c{1}:%L - %m%n
????????????
??????????????????????????????????????????????????????????????????????????????????????????????????????μ?appender???????????????????????????????????log4j.rootCategory??????file??appender??????root????????????logs/all.log????????
????log4j.rootCategory=INFO?? stdout?? file
????# root??????
????log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
????log4j.appender.file.file=logs/all.log
????log4j.appender.file.DatePattern='.'yyyy-MM-dd
????log4j.appender.file.layout=org.apache.log4j.PatternLayout
????log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss??SSS} %5p %c{1}:%L - %m%n
???????????
???????????????????????????????????????????????????????з??????磺
????????????package?????????????????????logs/my.log??appender??????com.didispace???μ?????????趨?DEBUG????appender??????????logs/my.log?????didifile??appender??
????# com.didispace???μ????????
????log4j.category.com.didispace=DEBUG?? didifile
????# com.didispace?μ???????
????log4j.appender.didifile=org.apache.log4j.DailyRollingFileAppender
????log4j.appender.didifile.file=logs/my.log
????log4j.appender.didifile.DatePattern='.'yyyy-MM-dd
????log4j.appender.didifile.layout=org.apache.log4j.PatternLayout
????log4j.appender.didifile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss??SSS} %5p %c{1}:%L ---- %m%n
?????????????????з????????ERROR?????????????????????У????????????????:
????log4j.logger.error=errorfile
????# error??????
????log4j.appender.errorfile=org.apache.log4j.DailyRollingFileAppender
????log4j.appender.errorfile.file=logs/error.log
????log4j.appender.errorfile.DatePattern='.'yyyy-MM-dd
????log4j.appender.errorfile.Threshold = ERROR
????log4j.appender.errorfile.layout=org.apache.log4j.PatternLayout
????log4j.appender.errorfile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss??SSS} %5p %c{1}:%L - %m%n
????????????????????spring boot??????log4j??????Щ?????÷??????????log4j???÷???????ο?log4j??????
????????spring boot?汾1.5.2???log4j2??????
???????log4j2??????
????????????????src/main/resources/log4j2.xml???????
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT" follow="true">
<PatternLayout>
<pattern>%d %p %C{1.} [%t] %m%n</pattern>
</PatternLayout>
</Console>
<File name="File" fileName="/Users/zk_chs/logtest/zk_chs.log">
<PatternLayout>
<pattern>%d %p %C{1.} [%t] %m%n</pattern>
</PatternLayout>
</File>
</Appenders>
<Loggers>
<Logger name="org.apache.catalina.util.LifecycleBase" level="error" />
<Logger name="org.apache.coyote.http11.Http11NioProtocol" level="warn" />
<Logger name="org.apache.tomcat.util.NET.NioSelectorPool" level="warn" />
<Logger name="org.hibernate.validator.internal.util.Version" level="warn" />
<Logger name="org.springframework" level="warn" />
<Logger name="com.github" level="debug" />
<Root level="info">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>
??????pom.xml????spring boot????????ж???
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<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-log4j2</artifactId>
</dependency>
????????application.properties????У?????????log???λ???
????logging.config=classpath:log4j2.xml
??????????????????????????????????????????????е???????<AppenderRef ref="File" />????
????ps:????spring boot??????????
??????java???м???
????import org.apache.logging.log4j.LogManager;
????import org.apache.logging.log4j.Logger;
????private static Logger logger = LogManager.getLogger(IndexInterceptor2.class.getName());
????????:
????The import org.apache.logging.log4j.LogManager cannot be resolved
??????????pom.xml??????????????????
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.2</version>
</dependency>
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11