logback配置
1.在maven pom文件中增加logback的依赖包
<!-- logback --> <dependency> <groupId>org.slf4j</groupId> <artifactId>jcl-over-slf4j</artifactId> <version>1.7.7</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.1.2</version> </dependency>
2.logback.xml的配置
讲logback.xml文件放到src/main/resources目录下
配置样例:
<?xml version="1.0" encoding="UTF-8"?> <!-- configuration file for LogBack (slf4J implementation) See here for more details: http://gordondickens.com/wordpress/2013/03/27/sawing-through-the-java-loggers/ --> <configuration scan="true" scanPeriod="30 seconds"> <property name="APP_NAME" value="thirdserver" /> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level [%file:%line] - %msg%n</pattern> </encoder> </appender> <!--Appendar详解: http://logback.qos.ch/manual/appenders.html#RollingFileAppender --> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>/export/logs/thirdserver/${APP_NAME}.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>/export/logs/thirdserver/${APP_NAME}.%d{yyyy-MM-dd}.%i.zip</fileNamePattern> <maxHistory>15</maxHistory> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <maxFileSize>10MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> <layout class="ch.qos.logback.classic.PatternLayout"> <!-- 格式说明:http://logback.qos.ch/manual/layouts.html#ClassicPatternLayout --> <Pattern>%d [%thread] %-5level [%file:%line] - %msg%n</Pattern> </layout> </appender> <root level="info"> <appender-ref ref="STDOUT" /> <appender-ref ref="FILE" /> </root> </configuration>