莫个银行项目中实际引用的logback实例,提供大家参考!!!!
[html] view
plaincopy
plaincopy
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- if debug set to true, context info always print
- otherwise the contex info will print when error occour -->
- <configuration scan="true" scanPeriod="60 seconds" debug="false">
- <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
- <layout class="ch.qos.logback.classic.PatternLayout">
- <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{40} - %msg%n</pattern>
- </layout>
- </appender>
- <!-- 所有日志文件-->
- <appender name="AllLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
- <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
- <fileNamePattern>log/abcchina/all/%d{yyyy-MM-dd}.log</fileNamePattern>
- <maxHistory>30</maxHistory>
- </rollingPolicy>
- <encoder>
- <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{40} - %msg%n</pattern>
- </encoder>
- </appender>
- <appender name="TaskLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
- <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
- <fileNamePattern>log/abcchina/task/%d{yyyy-MM-dd}.log</fileNamePattern>
- <maxHistory>30</maxHistory>
- </rollingPolicy>
- <encoder>
- <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{40} - %msg%n</pattern>
- </encoder>
- </appender>
- <appender name="SendLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
- <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
- <fileNamePattern>log/abcchina/send/%d{yyyy-MM-dd}.log</fileNamePattern>
- <maxHistory>30</maxHistory>
- </rollingPolicy>
- <encoder>
- <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{40} - %msg%n</pattern>
- </encoder>
- </appender>
- <!-- 为莫个包下的所有类指定Appender 这里也可以指定类名称例如:com.aa.bb.ClassName-->
- <logger name="com.aa.bb" >
- <appender-ref ref="TaskLog" />
- </logger>
- <logger name="com.aa.cc" >
- <appender-ref ref="SendLog" />
- </logger>
- <root level="INFO">
- <appender-ref ref="AllLog" />
- </root>
- </configuration>
补充:第二个例子
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration> <configuration scan="true" scanPeriod="1 seconds"> <!-- 控制台输出日志 --> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%-5level %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{100}[line:%L] - %msg%n</pattern> </encoder> </appender> <!-- 文件输出日志 (文件大小策略进行文件输出,超过指定大小对文件备份)--> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <!-- 过滤掉 TRACE 和 DEBUG 级别的日志:过滤低于INFO级别的--> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>INFO</level> </filter> <!-- <file>logs/waterapp.log</file> --> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <FileNamePattern>logs/waterapp.%d{yyyy-MM-dd}.log</FileNamePattern> <maxHistory>30</maxHistory> <!-- 保存30天 --> </rollingPolicy> <!--5MB自动压缩--> <!--triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> <maxFileSize>5MB</maxFileSize> </triggeringPolicy--> <encoder> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{100}[line:%L] - %msg%n</pattern> </encoder> </appender> <!-- --> <logger name="bingo" level="debug"/> <logger name="org.apache" level="ERROR"/> <logger name="org.springframework" level="ERROR"/> <logger name="org.lightframework" level="ERROR"/> <logger name="ch.qos.logback" level="ERROR"/> <root level="debug"> <appender-ref ref="STDOUT" /> </root> </configuration>