• logback使用配置


    一:logback.xml配置内容如下

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- Copyright 2010-2011 The myBatis Team Licensed under the Apache License, 
        Version 2.0 (the "License"); you may not use this file except in compliance 
        with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
        Unless required by applicable law or agreed to in writing, software distributed 
        under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES 
        OR CONDITIONS OF ANY KIND, either express or implied. See the License for 
        the specific language governing permissions and limitations under the License. -->
    <configuration scanPeriod="60 seconds" debug="false">
        <property name="LOG_HOME" value="${user.dir}/logs/patchtool/" />
    
        <!-- 控制台输出日志 -->
        <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
            <layout class="ch.qos.logback.classic.PatternLayout">
                <pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX} %level [%thread] [%logger{100}.%method:%line] - %msg%n</pattern>
                <charset>UTF-8</charset>
            </layout>
        </appender>
    
        <!-- 文件输出日志 (文件大小策略进行文件输出,超过指定大小对文件备份) -->
        <appender name="FILE-debug"
            class="ch.qos.logback.core.rolling.RollingFileAppender">
            <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
                <level>DEBUG</level>
            </filter>
            <File>${LOG_HOME}/debug.log</File>
            <!-- 日志回滚策略 -->
            <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
                <FileNamePattern>${LOG_HOME}/debug.%i.log</FileNamePattern>
                <MinIndex>1</MinIndex>
                <MaxIndex>10</MaxIndex>
            </rollingPolicy>
            <triggeringPolicy
                class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
                <MaxFileSize>25MB</MaxFileSize>
            </triggeringPolicy>
            <layout class="ch.qos.logback.classic.PatternLayout">
                <Pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX} %level [%thread] [%logger{50}.%method:%line] %msg%n</Pattern>
                <charset>UTF-8</charset>
            </layout>
        </appender>
    
        <appender name="FILE-error"
            class="ch.qos.logback.core.rolling.RollingFileAppender">
            <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
                <level>ERROR</level>
            </filter>
            <File>${LOG_HOME}/error.log</File>
            <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
                <FileNamePattern>${LOG_HOME}/error.%i.log</FileNamePattern>
                <MinIndex>1</MinIndex>
                <MaxIndex>10</MaxIndex>
            </rollingPolicy>
            <triggeringPolicy
                class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
                <MaxFileSize>25MB</MaxFileSize>
            </triggeringPolicy>
            <layout class="ch.qos.logback.classic.PatternLayout">
                <Pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX} %level [%thread] [%logger{50}.%method:%line] %msg%n</Pattern>
                <charset>UTF-8</charset>
            </layout>
        </appender>
    
        <appender name="FILE-info"
            class="ch.qos.logback.core.rolling.RollingFileAppender">
            <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
                <level>INFO</level>
            </filter>
            <File>${LOG_HOME}/@bic.patchtool.info.log</File>
            <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
                <FileNamePattern>${LOG_HOME}/@info.%i.log</FileNamePattern>
                <MinIndex>1</MinIndex>
                <MaxIndex>10</MaxIndex>
            </rollingPolicy>
            <triggeringPolicy
                class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
                <MaxFileSize>25MB</MaxFileSize>
            </triggeringPolicy>
            <layout class="ch.qos.logback.classic.PatternLayout">
                <Pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX} %level [%thread] [%logger{50}.%method:%line] %msg%n</Pattern>
                <charset>UTF-8</charset>
            </layout>
        </appender>
    
        <appender name="FILE-trace"
            class="ch.qos.logback.core.rolling.RollingFileAppender">
            <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
                <level>TRACE</level>
            </filter>
            <File>${LOG_HOME}/trace.log</File>
            <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
                <FileNamePattern>${LOG_HOME}/trace.%i.log</FileNamePattern>
                <MinIndex>1</MinIndex>
                <MaxIndex>10</MaxIndex>
            </rollingPolicy>
            <triggeringPolicy
                class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
                <MaxFileSize>25MB</MaxFileSize>
            </triggeringPolicy>
            <layout class="ch.qos.logback.classic.PatternLayout">
                <Pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX} %level [%thread] [%logger{50}.%method:%line] %msg%n</Pattern>
                <charset>UTF-8</charset>
            </layout>
        </appender>
    
        <!-- 项目代码日志 -->
        <logger name="com.hikvision" level="TRACE" additivity="false">
            <appender-ref ref="STDOUT" />
            <appender-ref ref="FILE-debug" />
            <appender-ref ref="FILE-info" />
            <appender-ref ref="FILE-error" />
            <appender-ref ref="FILE-trace" />
        </logger>
        
        <!-- 日志输出级别 -->
        <root level="TRACE">
            <appender-ref ref="STDOUT" />
        </root>
    
    </configuration>

    二:Maven依赖的配置如下

    <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </dependency>
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-core</artifactId>
            </dependency>
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-access</artifactId>
            </dependency>
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
            </dependency>
  • 相关阅读:
    Oracle 11g设置IP访问限制
    ORA-01940 无法删除当前已连接的用户之解决方案
    如何终止正在进行expdp导出数据的任务
    Oracle权限管理详解
    linux yum配置代理
    命令别名设置: alias, unalias
    Linux 桌面双击运行脚本
    变量内容的删除、取代与替换 (Optional)
    linux查看和修改PATH环境变量的方法
    文件系统及程序的限制关系: ulimit
  • 原文地址:https://www.cnblogs.com/sandyflower/p/9520372.html
Copyright © 2020-2023  润新知