log4j

pro

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:

<?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,768

posted @ 2019-04-28 07:45  纵不朽  阅读(252)  评论(0编辑  收藏  举报