log4j

proapache

log4j.appender.atguigu.File=org.apache.log4j.DailyRollingFileAppender
log4j.appender.atguigu.File.file=d:\\atguigu.log
log4j.appender.atguigu.File.DatePattern=.yyyy-MM-dd
log4j.appender.atguigu.File.layout=org.apache.log4j.PatternLayout
log4j.appender.atguigu.File.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p (%C{1}:%M) - %m%n

log4j.appender.atguigu.Console=org.apache.log4j.ConsoleAppender 
log4j.appender.atguigu.Console.layout=org.apache.log4j.PatternLayout    
log4j.appender.atguigu.Console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p (%C:%M) - %m%n 


log4j.rootLogger=warn,atguigu.Console,atguigu.File
#\u540e\u9762\u8fd8\u6709\u5148\u4e0d\u770b









#log4j.logger.com.atguigu=warn,atguigu.Console,atguigu.File


#log4j.logger.com.atguigu.dao=debug,atguigu.Console,atguigu.File

xml:app

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">


<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

    <appender name="log.console" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %5p (%C{1}:%M) - %m%n" />
        </layout>
        <!-- 
        <filter class="org.apache.log4j.varia.LevelRangeFilter"> 
                <param name="levelMin"         value="warn" /> 
                <param name="levelMax"         value="warn" /> 
                <param name="AcceptOnMatch" value="true" /> 
        </filter>
        -->
    </appender>

    <appender name="log.file" class="org.apache.log4j.DailyRollingFileAppender">
        <param name="File"             value="D:\\atguigu4XML.log" />
        <param name="Append"         value="true" />
        <param name="DatePattern"     value="'.'yyyy-MM-dd" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %5p (%C{1}:%M) - %m%n" />
        </layout>
        <!-- <filter class="org.apache.log4j.varia.LevelRangeFilter"> 
                <param name="levelMin"         value="info" /> 
                <param name="levelMax"         value="info" /> 
                <param name="AcceptOnMatch" value="true" /> 
            </filter> -->
    </appender>
    <!-- -->
    <logger name="com.atguigu" additivity="false">
        <level value="info" />
        <appender-ref ref="log.console" />
        <appender-ref ref="log.file" />
    </logger>
     
    <logger name="com.atguigu.dao" additivity="false">
        <level value="debug" />
        <appender-ref ref="log.console" />
        <appender-ref ref="log.file" />
    </logger>
    <!-- -->
    <root>
        <level value="debug" />
        <appender-ref ref="log.console" />
        <appender-ref ref="log.file" />
    </root>     
 

</log4j:configuration>

 

%m 輸出代碼中指定的消息
%p 輸出優先級,即DEBUG,INFO,WARN,ERROR,FATAL
%r 輸出自應用啓動到輸出該log信息耗費的毫秒數
%c 輸出所屬的類目,一般就是所在類的全名
%t 輸出產生該日誌事件的線程名
%n 輸出一個回車換行符,Windows平臺爲「\r\n」,Unix平臺爲「\n」
%d 輸出日誌時間點的日期或時間,默認格式爲ISO8601,也能夠在其後指定格式,
好比:%d{yyyy-MM-dd HH:mm:ss,SSS},輸出相似:2015-12-20 18:35:51,768ui

相關文章
相關標籤/搜索