logback.xml配置

logback是log4j的作者另外开发的一个日志系统,比log4j速度更快,更高效,配合slf4j,真是天衣无缝,I like it。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <!-- %.-1level 只显示信息级别的首字母,%-5level 左对齐显示信息级别全称 -->
            <!-- 如需自定义关键字,用 %mdc{键名} 表示,程序中用MDC.put("键名","键值")设置,可动态设置 [%logger:%line]-->
            <Pattern>[%date{HH:mm:ss}] [%-5level] --%mdc{client} %msg%n</Pattern>
        </encoder>>
    </appender>
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>log/log.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>log/log.%d{yyyy-MM-dd}.log</FileNamePattern>
        </rollingPolicy>
        <encoder>
            <!-- %-40(%-35logger{35}:%-4line) -->
            <Pattern>[%date{yyyy-MM-dd HH:mm:ss}] [%-5level] [%logger:%line] --%mdc{client} %msg%n</Pattern>
        </encoder>>
    </appender>
    <logger name="com.mchange" level="INFO"/>
    <logger name="org.springframework" level="WARN"/>
    <logger name="java.sql.Connection" level="DEBUG"/>
    <logger name="java.sql.ResultSet" level="INFO"/>
    <logger name="com.boaotech.util" level="DEBUG"/>
    <root level="TRACE">
        <appender-ref ref="STDOUT"/>
        <!-- appender-ref ref="FILE" / -->
    </root>
    <!-- appender name="FAILSQL" class="ch.qos.logback.core.FileAppender">
        <file>log/fail.sql.log</file>
        <encoder>
            <Pattern>%date{yyyy-MM-dd HH:mm:ss} %msg%n</Pattern>
        </encoder>
    </appender>
    <logger name="com.boaotech.osgi.posdb.FailSqlLog">
        <appender-ref ref="FAILSQL"/>
    </logger -->
</configuration>

你可能感兴趣的:(java)