码迷,mamicode.com
首页 > 其他好文 > 详细

log4j2配置实例[按小时记录日志文件]

时间:2015-09-18 18:49:32      阅读:694      评论:0      收藏:0      [点我收藏+]

标签:log4j2   log4j配置   java日志   

log4j2.xml文件配置实例:

<?xml version="1.0" encoding="UTF-8"?>
<configuration status="off">
    <properties>
        <!-- File base path -->
        <property name="LOG_HOME">/logs</property>
        <!-- App server name -->
        <property name="SERVER_NAME">cloud</property>
        <!-- Backup file path -->
        <property name="BACKUP_HOME">{LOG_HOME}/backup</property>
    </properties>

    <appenders>
        <!-- Console -->
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %logger{36}.%M@%L - %msg%n"/>
            <!--<PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %C{5} (%F:%L) - %msg%n"/>-->
        </Console>
        <!-- RollingFile -->
        <RollingRandomAccessFile name="RollingFile"
                                 fileName="${LOG_HOME}/${SERVER_NAME}"
                                 filePattern="${LOG_HOME}/${SERVER_NAME}.%d{yyyy-MM-dd-HH}.log">
            <PatternLayout pattern="%date{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36}.%M@%L - %msg%n"/>
            <Policies>
                <!--<TimeBasedTriggeringPolicy modulate="true" interval="24"/>-->
                <TimeBasedTriggeringPolicy/>
                <SizeBasedTriggeringPolicy size="200 MB"/>
            </Policies>
            <DefaultRolloverStrategy max="100"/>
        </RollingRandomAccessFile>
    </appenders>

    <loggers>
        <!-- Spring Loggers -->
        <logger name="org.springframework" level="info"/>
        <logger name="org.springframework.beans" level="info"/>
        <logger name="org.springframework.core" level="info"/>
        <logger name="org.springframework.context" level="info"/>
        <logger name="org.springframework.web" level="info"/>
        <logger name="org.springframework.batch" level="info"/>
        <logger name="org.springframework.integration" level="info"/>

        <!-- Apache Loggers -->
        <logger name="org.apache" level="info"/>
        <logger name="org.apache.http" level="info"/>
        <logger name="org.apache.shiro" level="info"/>
        <logger name="org.apache.solr" level="info"/>
        <logger name="org.apache.lucene" level="info"/>
        <logger name="org.apache.tomcat" level="info"/>
        <logger name="org.apache.commons" level="info"/>

        <!-- MyBatis Loggers -->
        <logger name="org.mybatis" level="info"/>
        <logger name="org.apache.ibatis" level="info"/>

        <!-- Alibaba Loggers -->
        <logger name="com.alibaba" level="info"/>
        <logger name="com.alibaba.druid" level="info"/>

        <!-- App Loggers -->
        <logger name="com.code.platform" level="debug" additivity="false">
            <appender-ref ref="Console"/>
            <appender-ref ref="RollingFile"/>
        </logger>

        <!-- Root Logger -->
        <root level="info">
            <appender-ref ref="Console"/>
            <appender-ref ref="RollingFile"/>
        </root>
    </loggers>
</configuration>


本文出自 “猪会飞” 博客,请务必保留此出处http://jiyanle.blog.51cto.com/6932197/1696039

log4j2配置实例[按小时记录日志文件]

标签:log4j2   log4j配置   java日志   

原文地址:http://jiyanle.blog.51cto.com/6932197/1696039

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!