• logback.xml 实例


     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <configuration debug="false" scan="true" scanPeriod="30 minutes">
     3 
     4     <!-- ==================================================================================== -->
     5     <property name="logDir" value="logs/" />
     6     <!-- 打印到控制台 -->
     7     <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
     8         <encoder>
     9             <pattern>%date{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level-%logger{5} - %msg%n</pattern>
    10         </encoder>
    11     </appender>
    12 
    13     <!-- ==================================================================================== -->
    14     <appender name="infolog" class="ch.qos.logback.core.rolling.RollingFileAppender">
    15         <filter class="ch.qos.logback.classic.filter.LevelFilter">
    16             <level>INFO</level>
    17             <onMatch>ACCEPT</onMatch>   
    18             <onMismatch>DENY</onMismatch>   
    19         </filter>
    20         <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
    21             <fileNamePattern>${logDir}/info/log.%d{yyyy-MM-dd.HH}.%i.log.gz
    22             </fileNamePattern>
    23             <!-- 限制文件最大保存时间为15天; 15*24=360 -->
    24             <maxHistory>360</maxHistory>
    25             <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
    26                 <!-- 当文件大小超过60M时触发滚动,这里设置60M -->
    27                 <maxFileSize>60MB</maxFileSize>
    28             </timeBasedFileNamingAndTriggeringPolicy>
    29         </rollingPolicy>
    30         <encoder>
    31             <pattern>%date{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level-%logger{5} - %msg%n</pattern>
    32         </encoder>
    33     </appender>
    34 
    35     <appender name="debuglog" class="ch.qos.logback.core.rolling.RollingFileAppender">
    36         <filter class="ch.qos.logback.classic.filter.LevelFilter">
    37             <level>DEBUG</level>
    38             <onMatch>ACCEPT</onMatch>
    39             <onMismatch>DENY</onMismatch>
    40         </filter>
    41         <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
    42             <fileNamePattern>${logDir}/debug/log.%d{yyyy-MM-dd.HH}.%i.log.gz
    43             </fileNamePattern>
    44             <!-- 限制文件最大保存时间为15天; 15*24=360 -->
    45             <maxHistory>360</maxHistory>
    46             <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
    47                 <!-- 当文件大小超过60M时触发滚动,这里设置60M -->
    48                 <maxFileSize>60MB</maxFileSize>
    49             </timeBasedFileNamingAndTriggeringPolicy>
    50         </rollingPolicy>
    51         <encoder>
    52             <pattern>%date{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level-%logger{5} - %msg%n</pattern>
    53         </encoder>
    54     </appender>
    55 
    56     <appender name="errorlog" class="ch.qos.logback.core.rolling.RollingFileAppender">
    57         <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
    58             <level>WARN</level>
    59         </filter>
    60         <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
    61             <fileNamePattern>${logDir}/error/log.%d{yyyy-MM-dd.HH}.%i.log.gz
    62             </fileNamePattern>
    63             <!-- 限制文件最大保存时间为15天; 15*24=360 -->
    64             <maxHistory>360</maxHistory>
    65             <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
    66                 <!-- 当文件大小超过60M时触发滚动,这里设置60M -->
    67                 <maxFileSize>60MB</maxFileSize>
    68             </timeBasedFileNamingAndTriggeringPolicy>
    69         </rollingPolicy>
    70         <encoder>
    71             <pattern>%date{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level-%logger{5} - %msg%n</pattern>
    72         </encoder>
    73     </appender>
    74 
    75 
    76     <!-- 异步日志配置 -->
    77     <appender name="infolog_async" class="ch.qos.logback.classic.AsyncAppender">
    78         <discardingThreshold>5000</discardingThreshold>
    79         <queueSize>50000</queueSize>
    80         <appender-ref ref="infolog" />
    81     </appender>
    82 
    83     <appender name="errorlog_async" class="ch.qos.logback.classic.AsyncAppender">
    84         <discardingThreshold>5000</discardingThreshold>
    85         <queueSize>50000</queueSize>
    86         <appender-ref ref="errorlog" />
    87     </appender>
    88 
    89 
    90     <root level="debug">
    91         <appender-ref ref="stdout" />
    92         <appender-ref ref="debuglog" />
    93         <appender-ref ref="infolog_async" />
    94         <appender-ref ref="errorlog_async" />
    95     </root>
    96 
    97 
    98 </configuration>
  • 相关阅读:
    python报以下错误:TypeError: 'int' object is not subscriptable
    C# Func与Action
    C#调用C++的DLL 尝试写入受保护的内存
    C#调用C++的dll EntryPointNotFoundException
    C# 拖拽事件
    C#操作Access数据库中遇到的问题(待续)
    Winform 中写代码布局中遇到的控件遮盖问题
    thinkphp6执行流程(一)
    xdebug调试过程中apache500超时
    禁用phpcookie以后如何使用Session
  • 原文地址:https://www.cnblogs.com/empireghost/p/4613397.html
Copyright © 2020-2023  润新知