logback使用
logback使用
lgscofield 发表于3年前
logback使用
  • 发表于 3年前
  • 阅读 527
  • 收藏 5
  • 点赞 0
  • 评论 0

腾讯云 新注册用户 域名抢购1元起>>>   

摘要: logback配置文件
<?xml version="1.0" encoding="UTF-8" ?>
<!-- @author liguohua -->
<configuration>
    <property name="logs.dir" value="/tmp/logs/xweb"/>

    <!-- 下面appender表示输出到控制台 -->
    <appender name="StdoutLogger" class="ch.qos.logback.core.ConsoleAppender">
        <!-- 设置级别过滤器 -->
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <!-- level级别的日志才会被处理,其他级别不处理 -->
            <level>DEBUG</level>
            <!-- 用于配置符合条件的操作 -->
            <onMatch>ACCEPT</onMatch>
            <!-- 用于配置不符合条件的操作 -->
            <onMismatch>DENY</onMismatch>
        </filter>
        <!-- encoder指定编码格式,并根据指定的pattern输出日志信息 -->
        <encoder charset="UTF-8">
            <!-- pattern指定日志的输出格式 -->
            <pattern>[%-5level] %date{yyyy-MM-dd HH:mm:ss} %logger \(%file:%line\) - %message%n</pattern>
        </encoder>
    </appender>

    <appender name="AllLogger" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${logs.dir}/AllLog.log</file>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>INFO</level>
        </filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>AllLog.%d{yyyy-MM-dd}.log</fileNamePattern>
        </rollingPolicy>
        <encoder>
            <pattern>[%-5level] %date{yyyy-MM-dd HH:mm:ss} %logger \(%file:%line\) - %message%n</pattern>
        </encoder>
    </appender>

    <appender name="WarnLogger" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <!--<file>${logs.dir}/WARNLog-${byDate}.log</file> -->
        <file>${logs.dir}/WARNLog.log</file>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>WARN</level>
        </filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>WARNLog.%d{yyyy-MM-dd}.log</fileNamePattern>
            <maxHistory>30</maxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>[%-5p] %d{yyyy-MM-dd HH:mm:ss} %logger.%method \(%file:%line\) - %message%n</pattern>
        </encoder>
    </appender>

    <appender name="SqlLogLogger" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${logs.dir}/SqlLog.log</file>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>DEBUG</level>
        </filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>SqlLog.%d{yyyy-MM-dd}.log</fileNamePattern>
            <maxHistory>30</maxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>[%-5p] %d{yyyy-MM-dd HH:mm:ss} %logger \(%file:%line\) - %message%n</pattern>
        </encoder>
    </appender>
    <!-- <appender name="SOCKET" class="ch.qos.logback.classic.net.SocketAppender"> <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
    <level>INFO</level> </filter> <RemoteHost>127.0.0.1</RemoteHost> <Port>4445</Port> <ReconnectionDelay>10000</ReconnectionDelay>
    <IncludeCallerData>true</IncludeCallerData> </appender> -->
    <!-- MyBatis 日志配置 -->
    <logger name="org.apache.ibatis" level="DEBUG" additivity="true">
        <appender-ref ref="SqlLogLogger"/>
    </logger>
    <logger name="org.apache.ibatis.builder.xml.XMLConfigBuilder" level="ERROR" additivity="true">
        <appender-ref ref="SqlLogLogger"/>
    </logger>
    <!-- org.apache.ibatis.logging.jdbc.PreparedStatementLogger -->
    <logger name="java.sql.PreparedStatement" level="DEBUG" additivity="false">
        <appender-ref ref="SqlLogLogger"/>
    </logger>
    <!-- org.apache.ibatis.logging.jdbc.StatementLogger -->
    <logger name="java.sql.Statement" level="DEBUG" additivity="false">
        <appender-ref ref="SqlLogLogger"/>
    </logger>
    <logger name="org.apache.ibatis.logging.slf4j" level="TRACE">
        <appender-ref ref="StdoutLogger"/>
    </logger>
    <!-- hibernate 日志配置 -->
    <logger name="org.hibernate" level="WARN" additivity="false">
        <appender-ref ref="SqlLogLogger"/>
    </logger>
    <logger name="org.hibernate.type" level="TRACE" additivity="false">
        <appender-ref ref="SqlLogLogger"/>
    </logger>
    <logger name="org.hibernate.pretty.Printer" level="DEBUG" additivity="false">
        <appender-ref ref="SqlLogLogger"/>
    </logger>
    <!-- org.hibernate.jdbc.util.SQLStatementLogger -->
    <logger name="org.hibernate.SQL" level="DEBUG" additivity="false">
        <appender-ref ref="SqlLogLogger"/>
    </logger>
    <logger name="org.hibernate.persister.entity.AbstractEntityPersister" level="ERROR" additivity="false">
        <appender-ref ref="SqlLogLogger"/>
    </logger>
    <logger name="jsp.request" level="DEBUG" additivity="false">
        <appender-ref ref="StdoutLogger"/>
    </logger>
    <root level="DEBUG">
        <appender-ref ref="StdoutLogger"/>
        <!--<appender-ref ref="AllLogger"/>-->
        <!--<appender-ref ref="SqlLogLogger"/>-->
        <!--<appender-ref ref="WarnLogger"/>-->
    </root>
</configuration>



标签: logback
共有 人打赏支持
lgscofield
粉丝 20
博文 105
码字总数 62676
×
lgscofield
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: