logback.xml 示例

一、开发环境:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender"> <layout class="ch.qos.logback.classic.PatternLayout"> <pattern>%-20(%d{HH:mm:ss.SSS} [%thread]) %-5level %logger{80} - %msg%n</pattern> </layout> </appender> <logger name="java.sql.PreparedStatement" level="DEBUG" /> <logger name="org.springframework.ui.freemarker" level="DEBUG" /> <root level="INFO"> <appender-ref ref="stdout" /> </root> </configuration>

 

 

二、生产环境:

<?xml version="1.0" encoding="UTF-8"?> <configuration> <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>logs/xxx.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>logs/xxx.%d{yyyy-MM-dd}.log.zip</fileNamePattern> </rollingPolicy> <layout class="ch.qos.logback.classic.PatternLayout"> <pattern>%-20(%d{HH:mm:ss.SSS} [%thread]) %-5level %logger{80} - %msg%n</pattern> </layout> </appender> <root level="WARN"> <appender-ref ref="file" /> </root> </configuration>

 

 

slf4j + logback 比commons logging + log4j要方便很多。更重要是带了性能的提升

不爽是,这个配置文件没有schema,甚至一个简陋的dtd都没有提供,于是乎不得不忍受eclipse里面黄黄的warning


2012/03/16 更新

http://logback.qos.ch/codes.html#layoutInsteadOfEncoder

有标签更换!!!

你可能感兴趣的:(thread,log4j,layout,Class,slf4j,encoding)