您好,登錄后才能下訂單哦!
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>
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。