欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

LOGBACK的配置和使用

程序员文章站 2022-07-03 19:15:21
...
项目用到了logback,我自己参照了BLOG

http://www.cnblogs.com/luowei010101/archive/2012/01/04/2312438.html


logback的使用需要三个包

slf4j-api-1.6.0.jar
logbcak-classic-0.9.21.jar
logbcak-core-0.9.21.jar


我的logback.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="5 minutes">

<appender name="stdoutAppender" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{HH:mm:ss.SSS} \(%thread\) %-6level- %logger{36}: %msg%n</Pattern>
</layout>
</appender>

<!-- 在服务器端的配置 -->
<property file="/opt/xxx/xxx/config/applicationContext.properties" />

<!-- 在本地的配置
<property file="src\main\resources\applicationContext.properties" />
-->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${gui.log.dir}/${gui.log.name}</file>
<!-- <file>${gui.log.dir}\${gui.log.name}</file> -->
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>${gui.log.dir}/${gui.log.rolling.format}</fileNamePattern>
<!-- <fileNamePattern>${gui.log.dir}\${gui.log.rolling.format}</fileNamePattern> -->
<minIndex>${gui.log.file.min}</minIndex>
<maxIndex>${gui.log.file.max}</maxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>${gui.log.max.file.size}</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>%d{yyyy/MM/dd HH:mm:ss.SSS} \(%thread\) %-6level- %logger{36}: %msg%n</pattern>
</encoder>
</appender>


<root level="INFO">
<appender-ref ref="stdoutAppender" />
<appender-ref ref="FILE" />
</root>

<logger name="com.digia" level="DEBUG">
<appender-ref ref="FILE" />
</logger>
</configuration>


使用的applicationContext.properties配置

#GUI log store path
gui.log.dir=/opt/xxx/xxx/logs
#GUI log name
gui.log.name=xxx.log
#GUI log file min
gui.log.file.min=1
#GUI log file max
gui.log.file.max=5
#GUI log file max size
gui.log.max.file.size=10MB
#GUI log file rolling format
gui.log.rolling.format=xxx.%i.log
相关标签: logback