Java日志logback使用
pom中添加:
<dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.21</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.1.7</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-core</artifactId> <version>1.1.7</version> </dependency>
logback日志的配用:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration> <configuration> <property resource="properties/logback.properties" /> <!--控制台输出 --> <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%date{yyyy-MM-dd HH:mm:ss.SSS} %-5level[%thread]%logger{56}.%method\(\):%L -%msg%n</pattern> </encoder> </appender> <!--文件输出 --> <appender name="logfile" class="ch.qos.logback.core.rolling.RollingFileAppender"> <Encoding>UTF-8</Encoding> <File>${log.base}comment.log</File> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <FileNamePattern>${log.base}comment.%d{yyyy-MM-dd}.log.zip</FileNamePattern> </rollingPolicy> <encoder> <pattern>%date|%msg%n</pattern> </encoder> </appender> <root> <level value="${log.level}" /> <appender-ref ref="${log.appender.ref}" /> </root> </configuration>
log.base=d:/logs/ log.level=DEBUG log.appender.ref=stdout