logback 설정 및 사용

9965 단어 logback
Read it chapter by chapter. It’s simple. http://logback.qos.ch/manual/introduction.html
sample
<?xml version="1.0" encoding="UTF-8"?>

<configuration scan="true" scanPeriod="30 seconds">

    <!--             ,           。                      。 -->
    <property resource="log.properties" />

    <timestamp key="timeShow" datePattern="yyyy-MM-dd HH:mm:ss.SSS"/>

    <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
        <encoder charset="UTF-8">
            <pattern>${timeShow} [%thread] %-5level %logger - %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="service" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- ${var:-xxxx} [:-]         -->
            <fileNamePattern>${log.dir:-F:/temp}/logs/${log.service:-service}-%d{yyyy-MM-dd}.log</fileNamePattern>
            <maxHistory>10</maxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>${timeShow} [%thread] %-5level %logger - %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="RollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- ${var:-xxxx} [:-]         -->
            <fileNamePattern>${log.dir:-F:/temp}/logs/${log.module:-system}-%d{yyyy-MM-dd}.log</fileNamePattern>
            <maxHistory>10</maxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>${timeShow} [%thread] %-5level %logger - %msg%n</pattern>
        </encoder>
    </appender>


    <logger name="org.apache.zookeeper" level="WARN" />
    <logger name="org.jboss.resteasy" level="DEBUG" />
    <logger name="com.ibatis" level="DEBUG" />
    <logger name="com.ibatis.common.jdbc.SimpleDataSource" level="DEBUG" />
    <logger name="com.ibatis.common.jdbc.ScriptRunner" level="DEBUG" />
    <logger name="com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate" level="DEBUG" />
    <logger name="java.sql.Connection" level="DEBUG" />
    <logger name="java.sql.Statement" level="DEBUG" />
    <logger name="java.sql.PreparedStatement" level="DEBUG" />

    <!--            additivity=true                -->
    <logger name="com.swq.cloud.core.service" level="${log.service.level:-INFO}" additivity="{log.service.additivity:-true}">
        <appender-ref ref="service" />
    </logger>
    <root level="INFO">
        <appender-ref ref="stdout" />
        <appender-ref ref="RollingFile" />
    </root>

</configuration>

log.properties
#        
log.dir=F:\\temp\\idc
#          
log.module=core.system
#        
log.service=core.service
#        
log.service.level=DEBUG
#    level           
log.service.additivity=true

좋은 웹페이지 즐겨찾기