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


原文链接: http://blog.csdn.net/kimsoft/article/details/4035117

你可能感兴趣的:(logback.xml 示例)