Spring Boot 集成日志 logging sl4j
1.配置:src/main/resources/application.properties
logging.config=classpath:logback-spring.xml
- logback-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--scan:当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true。-->
<!--scanPeriod:设置监测配置文件是否有修改的时间间隔,如果没有给出时间单位,默认单位是毫秒。当scan为true时,此属性生效。默认的时间间隔为1分钟。-->
<!--debug:当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false。-->
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<property name="APP_NAME" value="h5agent"/>
<contextName>${APP_NAME}</contextName>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<jmxConfigurator/>
<logger name="com.alibaba.sinfo.h5.agent" level="INFO"/>
<logger name="org.springframework.web" level="INFO"/>
<appender name="dailyRollingFileAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rolling over -->
<FileNamePattern>${user.home}/logs/${APP_NAME}.%d{yyyy-MM-dd}.log</FileNamePattern>
<!-- 保持 30 days' 日志 log history -->
<maxHistory>30</maxHistory>
</rollingPolicy>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
<encoder>
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{35} - %msg %n</Pattern>
</encoder>
</appender>
<!--TRACE, DEBUG, INFO, WARN, ERROR-->
<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
<appender-ref ref="dailyRollingFileAppender"/>
</root>
</configuration>
- dependencies中添加依赖
dependencies {
compile('org.springframework.boot:spring-boot-starter-logging')
}
完整工程示例:
网友评论