• log4j.xml


    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
    <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
    <!--****************************** -->
    <!-- console define -->
    <!--****************************** -->
    <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern"
    value="[%d{dd HH:mm:ss,SSS} %-5p] [%t]
    %c{2} - %m%n" />
    </layout>
    <filter class="org.apache.log4j.varia.LevelRangeFilter">
    <param name="levelMin" value="DEBUG" />
    <param name="levelMax" value="ERROR" />
    <param name="AcceptOnMatch" value="true" />
    </filter>
    </appender>

    <!-- [公共Appender]汇总错误 -->
    <appender name="ERROR-APPENDER" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="encoding" value="GBK" />
    <param name="File" value="/opt/logs/open/error.log" />
    <param name="Threshold" value="error" />
    <param name="DatePattern" value="'.'yyyy-MM-dd" />
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern"
    value="[%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS}
    method:%l%n%m%n" />
    </layout>
    </appender>

    <!-- [公共Appender] 汇总警告 -->
    <appender name="WARN-APPENDER" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="encoding" value="GBK" />
    <param name="File" value="/opt/logs/open/warn.log" />
    <param name="Threshold" value="warn" />
    <param name="DatePattern" value="'.'yyyy-MM-dd" />
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern"
    value="[%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS}
    method:%l%n%m%n" />
    </layout>
    <filter class="org.apache.log4j.varia.LogLevelMatchFilter">
    <param name="LogLevelToMatch" value="warn" />
    <param name="AcceptOnMatch" value="true" />
    </filter>
    </appender>

    <!--默认日志-->
    <appender name="DEFAULT-APPENDER" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="encoding" value="UTF-8" />
    <param name="File" value="/opt/logs/open/default.log" />
    <param name="DatePattern" value="'.'yyyy-MM-dd" />
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern"
    value="[%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n" />
    </layout>
    </appender>

    <!--******************************* -->
    <!-- 应用 -->
    <!--******************************* -->

    <!-- api信息日志 -->
    <appender name="DEFAULT-API-APPENDER" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="encoding" value="UTF-8" />
    <param name="File" value="/opt/logs/open/open-api.log" />
    <param name="DatePattern" value="'.'yyyy-MM-dd" />
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="[%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} %m%n" />
    </layout>
    </appender>

    <!-- service日志 -->
    <appender name="DEFAULT-SERVICE-APPENDER" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="encoding" value="UTF-8" />
    <param name="File" value="/opt/logs/open/open-service.log" />
    <param name="DatePattern" value="'.'yyyy-MM-dd" />
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="[%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} %m%n" />
    </layout>
    </appender>

    <!-- web日志 -->
    <appender name="DEFAULT-WEB-APPENDER" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="encoding" value="UTF-8" />
    <param name="File" value="/opt/logs/open/open-web.log" />
    <param name="DatePattern" value="'.'yyyy-MM-dd" />
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="[%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} %m%n" />
    </layout>
    </appender>

    <!--****************************** -->
    <!-- dispatch to the log file -->
    <!--****************************** -->

    <!-- api -->
    <logger name="DEFAULT-API-APPENDER" additivity="false">
    <level value="INFO" />
    <appender-ref ref="DEFAULT-API-APPENDER" />
    <appender-ref ref="DEFAULT-APPENDER" />
    </logger>

    <logger name="com.xcm.open.api" additivity="false">
    <level value="INFO" />
    <appender-ref ref="DEFAULT-API-APPENDER" />
    <appender-ref ref="DEFAULT-APPENDER" />
    </logger>

    <!-- service -->
    <logger name="DEFAULT-SERVICE-APPENDER" additivity="false">
    <level value="INFO" />
    <appender-ref ref="DEFAULT-SERVICE-APPENDER" />
    <appender-ref ref="DEFAULT-APPENDER" />
    </logger>

    <logger name="com.xcm.open.core.service" additivity="false">
    <level value="INFO" />
    <appender-ref ref="DEFAULT-SERVICE-APPENDER" />
    <appender-ref ref="DEFAULT-APPENDER" />
    </logger>

    <!-- web -->
    <logger name="DEFAULT-WEB-APPENDER" additivity="false">
    <level value="INFO" />
    <appender-ref ref="DEFAULT-WEB-APPENDER" />
    <appender-ref ref="DEFAULT-APPENDER" />
    </logger>

    <logger name="com.xcm.open.web" additivity="false">
    <level value="INFO" />
    <appender-ref ref="DEFAULT-WEB-APPENDER" />
    <appender-ref ref="DEFAULT-APPENDER" />
    </logger>

    <!-- sql打印-->
    <logger name="org.springframework" additivity="false">
    <level value="ERROR" />
    <appender-ref ref="CONSOLE" />
    <appender-ref ref="DEFAULT-APPENDER" />
    </logger>
    <logger name="org.apache.ibatis" additivity="false">
    <level value="DEBUG" />
    <appender-ref ref="CONSOLE" />
    <appender-ref ref="DEFAULT-APPENDER" />
    </logger>
    <logger name="java.sql.Connection" additivity="false">
    <level value="DEBUG"/>
    <appender-ref ref="CONSOLE" />
    <appender-ref ref="DEFAULT-APPENDER" />
    </logger>
    <logger name="java.sql.Statement" additivity="false">
    <level value="DEBUG" />
    <appender-ref ref="CONSOLE" />
    <appender-ref ref="DEFAULT-APPENDER" />
    </logger>
    <logger name="java.sql.PreparedStatement" additivity="false">
    <level value="DEBUG" />
    <appender-ref ref="CONSOLE" />
    <appender-ref ref="DEFAULT-APPENDER" />
    </logger>


    <!--****************************** -->
    <!-- the root set -->
    <!--****************************** -->
    <root>
    <level value="INFO" />
    <appender-ref ref="CONSOLE" />
    <appender-ref ref="DEFAULT-APPENDER" />
    <appender-ref ref="ERROR-APPENDER" />
    </root>

    </log4j:configuration>

  • 相关阅读:
    Java Web三层架构设计深思
    编译C源码软件需要的工具
    Hibernate之表间关系
    CSS之颜色字体
    主流的微服务框架
    CSS布局思考
    Android创建新项目及开发
    Google工程师解析Android系统架构
    java多线程实用操作
    Spring IOC/DI/注解
  • 原文地址:https://www.cnblogs.com/yanghuiping/p/5509437.html
Copyright © 2020-2023  润新知