spring boot log
阿新 • • 發佈:2018-01-24
layout conf version 存在 build int target tar -m demo:
https://github.com/xiaosawuhen/spring-boot-log
spring boot log存在兩種形式
1.使用默認的logback
直接在application.properties中設置
## spring boot log4j logging.level.org.springframework.web=INFO logging.level.guru.springframework.blogs.controllers=INFO logging.level.org.hibernate=ERROR logging.file=logs/spring-boot-logging.log
2.使用log4j
pom.xml
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> </parent> <properties> <java.version>1.8</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</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> </dependencies>
application.properties
logging.config=classpath:log4j2.xml
log4j2.xml
<?xml version="1.0" encoding="UTF-8" ?> <configuration status="WARN"> <!--全局參數--> <Properties> <Property name="pattern">%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n</Property> </Properties> <Loggers> <Root level="DEBUG"> <AppenderRef ref="console"></AppenderRef> <AppenderRef ref="rolling_file"></AppenderRef> <AppenderRef ref="file"></AppenderRef> </Root> </Loggers> <Appenders> <Console name="console" target="SYSTEM_OUT" follow="true"> <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/> <PatternLayout> <Pattern>${pattern}</Pattern> </PatternLayout> </Console> <RollingFile name="rolling_file" fileName="logs/info.log" filePattern="${log4j2.root.path}_%d{yyyy-MM-dd}.log"> <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/> <PatternLayout> <Pattern>${pattern}</Pattern> </PatternLayout> <Policies> <!-- <TimeBasedTriggeringPolicy interval="1"/> --> <SizeBasedTriggeringPolicy size="1000 KB"/> </Policies> </RollingFile> <File name="file" fileName="logs/current.log"> <ThresholdFilter level="DEBUG" onMatch="ACCEPT" onMismatch="DENY"/> <PatternLayout> <Pattern>${pattern}</Pattern> </PatternLayout> </File> </Appenders> </configuration>
spring boot log