Customize the log4j2 filter and output the log to the specified file

2021-10-14 11:21作者:admin来源:未知>次阅读

because you need to filter and exclude logs of some specified classes from existing logs at a certain level, all the user-defined log filters of log4j are used.

original log content:

% 26lt;? xml version=" 1.0"  encoding=" UTF-8"?% 26gt;% 26lt;!-- Log level and priority: off> FATAL >  ERROR >  WARN >  INFO >  DEBUG >  TRACE >  ALL -->% 26lt;!--  Status: This is used to set the internal information output of log4j2. It can not be set. When it is set to trace, you will see various internal detailed outputs of log4j2. It is off by default \t  Monitor interval: log4j can automatically detect the modification of the configuration file and reconfigure itself, and set the interval seconds. The unit is s and the minimum is 5S \t % D {yyyy MM DD HH: mm: SS, SSS}: log production time% P: log output format% C: name of logger% m: log content, i.e. logger.info (% 26#34; message% 26#34;) %N: line feed% C: Java class name% l: number of lines where log output is located% m: method name where log output is located hostname: local machine name hostaddress: local IP address --% 26gt;% 26lt; configuration status=" debug"  monitorInterval=" 1"% 26gt; \t% 26lt; properties> \t\t% 26lt;!--  Configuration log file output directory --% 26gt; \t\t% 26lt; property name=" LOG_ HOME"% 26gt;/ utle/zhelidu/log4j</ property> \t\t% 26lt;!--  Log backup directory --% 26gt; \t\t% 26lt; property name=" BACKUP_ HOME"% 26gt; backup</ property> \t\t% 26lt;!--  Suffix of log backup file --% 26gt; \t\t% 26lt; property name=" BACKUP_ FILE_ NAME_ SUFFIX"% 26gt;% 26lt;/ property> \t\t% 26lt;!--  Log name, here -i --% 26gt; \t\t% 26lt; property name=" SERVER_ NAME"% 26gt; zhelidu</ property> \t\t% 26lt;!--  Minimum unit of log cutting --% 26gt; \t\t% 26lt; property name=" EVERY_ FILE_ SIZE"% 26gt; 50M</ property> \t\t% 26lt;!--  Log output level --% 26gt; \t\t% 26lt; property name=" OUTPUT_ LOG_ LEVEL"% 26gt; DEBUG</ property> \t\t% 26lt;!--  Log output format --% 26gt; \t\t% 26lt; property name=" PATTERN"% 26gt;% date{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %level [%C

.%M] - %msg%n</ property> \t\t% 26lt;!-- Log level of logger output --% 26gt; \t\t% 26lt; property name=" LOGGER_ LEVEL"% 26gt; DEBUG</ property> \t\t% 26lt;!-- Backup folder name folder --% 26gt; \t\t% 26lt; property name=" BACK_ FOLDER"% 26gt;% d{yyyyMMdd}</ property> \t\t% 26lt;!--% 26lt; property name=" BACK_ FOLDER"% 26gt;% d{yyyyMMddHH}</ property>--% 26gt; \t\t% 26lt;!-- Number of same log files reserved --% 26gt; \t\t% 26lt; property name=" MAX"% 26gt; 20</ property> \t\t% 26lt;!-- The maximum number of levels of the directory to access. A value of 0 means that only the starting file (the base path itself) is accessed unless rejected by the security manager. \t\t\t Integer.MAX_ The value of value indicates that all levels should be accessed. The default is 1, which means to specify the files in the base directory. --% 26gt; \t\t% 26lt; property name=" MAXDEPTH"% 26gt; 5</ property> \t\t% 26lt;!-- How long does the abnormal log need to be deleted for more than 10 days --% 26gt; \t\t% 26lt; property name=" AGE"% 26gt; 30d</ property> \t\t% 26lt;!-- How long do abnormal logs need to be deleted? Run at 0:00 every day --% 26gt; \t\t% 26lt; property name=" SCHEDULE"% 26gt; 0 0 0 * * ?% 26lt;/ property> \t% 26lt;/ properties> \t\t% 26lt; appenders> \t\t% 26lt;!-- Configuration of this output console --% 26gt; \t\t% 26lt; Console name=" Console" target=" SYSTEM_ OUT" follow=" true"% 26gt; \t\t\t% 26lt;!-- Format of output log --% 26gt; \t\t\t% 26lt; PatternLayout pattern="$ {PATTERN}" /% 26gt; \t\t% 26lt;/ Console> \t\t% 26lt;!-- Show only error level information --% 26gt; \t\t% 26lt; RollingFile name=" RollingFileError" \t\t\t\t\t fileName="$ {LOG_HOME}/${SERVER_NAME}_ error.log" \t\t\t\t\t filePattern="$ {LOG_HOME}/${BACKUP_HOME}/error/${BACK_FOLDER}/${SERVER_NAME}_ error-%i.log${BACKUP_FILE_NAME_SUFFIX}"% 26gt; \t\t\t% 26lt; PatternLayout pattern="$ {PATTERN}" /% 26gt; \t\t\t% 26lt; Policies> \t\t\t\t% 26lt; SizeBasedTriggeringPolicy size="$ {EVERY_FILE_SIZE}" /% 26gt; \t\t\t\t% 26lt; TimeBasedTriggeringPolicy interval=" 1" modulate=" true" /% 26gt; \t\t\t% 26lt;/ Policies> \t\t\t% 26lt; Filters> \t\t\t\t% 26lt; ThresholdFilter level=" error" onMatch=" ACCEPT" onMismatch=" DENY" /% 26gt; \t\t\t% 26lt;/ Filters> \t\t\t% 26lt; CronTriggeringPolicy schedule="$ {SCHEDULE}"/% 26gt; \t\t\t% 26lt; DefaultRolloverStrategy max="$ {MAX}"% 26gt; \t\t\t\t% 26lt; Delete basePath="$ {LOG_HOME}" maxDepth="$ {MAXDEPTH}"% 26gt; \t\t\t\t\t% 26lt; IfFileName glob="$ {BACKUP_HOME}/error/*/*.log*" /% 26gt; \t\t\t\t\t% 26lt; IfLastModified age="$ {AGE}" /% 26gt; \t\t\t\t% 26lt;/ Delete> \t\t\t% 26lt;/ DefaultRolloverStrategy> \t\t% 26lt;/ RollingFile> \t\t% 26lt;!-- Display only the information of warn level, suffix --% 26gt; \t\t% 26lt; RollingFile name=" RollingFileWarn" \t\t\t\t\t fileName="$ {LOG_HOME}/${SERVER_NAME}_ warn.log" \t\t\t\t\t filePattern="$ {LOG_HOME}/${BACKUP_HOME}/warn/${BACK_FOLDER}/${SERVER_NAME}_ warn-%i.log${BACKUP_FILE_NAME_SUFFIX}"% 26gt; \t\t\t% 26lt; PatternLayout pattern="$ {PATTERN}" /% 26gt; \t\t\t% 26lt; Policies> \t\t\t\t% 26lt; SizeBasedTriggeringPolicy size="$ {EVERY_FILE_SIZE}" /% 26gt; \t\t\t\t% 26lt; TimeBasedTriggeringPolicy interval=" 1" modulate=" true" /% 26gt; \t\t\t% 26lt;/ Policies> \t\t\t% 26lt; Filters> \t\t\t\t% 26lt;!-- \t\t\t\t Use a custom filter to filter out the logs of the specified class \t\t\t\t --% 26gt; \t\t\t\t% 26lt; ThresholdFilter level=" error" onMatch=" DENY" onMismatch=" NEUTRAL" /% 26gt; \t\t\t\t% 26lt; ThresholdFilter level=" warn" onMatch=" ACCEPT" onMismatch=" DENY"/% 26gt; \t\t\t% 26lt;/ Filters> \t\t\t% 26lt; CronTriggeringPolicy schedule="$ {SCHEDULE}"/% 26gt; \t\t\t% 26lt; DefaultRolloverStrategy max="$ {MAX}"% 26gt; \t\t\t\t% 26lt; Delete basePath="$ {LOG_HOME}" maxDepth="$ {MAXDEPTH}"% 26gt; \t\t\t\t\t% 26lt; IfFileName glob="$ {BACKUP_HOME}/warn/*/*.log*" /% 26gt; \t\t\t\t\t% 26lt; IfLastModified age="$ {AGE}" /% 26gt; \t\t\t\t% 26lt;/ Delete> \t\t\t% 26lt;/ DefaultRolloverStrategy> \t\t% 26lt;/ RollingFile> \t\t% 26lt;!-- Only info level information is displayed --% 26gt; \t\t% 26lt; RollingFile name=" RollingFileInfo" \t\t\t\t\t fileName="$ {LOG_HOME}/${SERVER_NAME}_ info.log" \t\t\t\t\t filePattern="$ {LOG_HOME}/${BACKUP_HOME}/info/${BACK_FOLDER}/${SERVER_NAME}_ info-%i.log${BACKUP_FILE_NAME_SUFFIX}"% 26gt; \t\t\t% 26lt; PatternLayout pattern="$ {PATTERN}" /% 26gt; \t\t\t% 26lt; Policies> \t\t\t\t% 26lt; SizeBasedTriggeringPolicy size="$ {EVERY_FILE_SIZE}" /% 26gt; \t\t\t\t% 26lt; TimeBasedTriggeringPolicy interval=" 1" modulate=" true" /% 26gt; \t\t\t% 26lt;/ Policies> \t\t\t% 26lt; Filters> \t\t\t\t% 26lt;!-- \t\t\t\t Use a custom filter to filter out the logs of the specified class \t\t\t\t --% 26gt; \t\t\t\t% 26lt; ThresholdFilter level=" warn" onMatch=" DENY" onMismatch=" NEUTRAL" /% 26gt; \t\t\t\t% 26lt; ThresholdFilter level=" info" onMatch=" ACCEPT" onMismatch=" DENY"/% 26gt; \t\t\t% 26lt;/ Filters> \t\t\t% 26lt; CronTriggeringPolicy schedule="$ {SCHEDULE}"/% 26gt; \t\t\t% 26lt; DefaultRolloverStrategy max="$ {MAX}"% 26gt; \t\t\t\t% 26lt; Delete basePath="$ {LOG_HOME}" maxDepth="$ {MAXDEPTH}"% 26gt; \t\t\t\t\t% 26lt; IfFileName glob="$ {BACKUP_HOME}/info/*/*.log*" /% 26gt; \t\t\t\t\t% 26lt; IfLastModified age="$ {AGE}" /% 26gt; \t\t\t\t% 26lt;/ Delete> \t\t\t% 26lt;/ DefaultRolloverStrategy> \t\t% 26lt;/ RollingFile> \t\t% 26lt;!-- This will print out all info and below levels of information. Each time the size exceeds size, the size log will be automatically saved under the folder established by year month and compressed as an archive --% 26gt; \t\t% 26lt;!-- It is important that if there are multiple thresholdfilters, filters are required. At the same time, in filters, first filter the non-conforming log levels, first deny the unnecessary ones, and then accept the required log levels. This order cannot be reversed. --% 26gt; \t\t% 26lt; RollingFile name=" RollingFile" \t\t\t fileName="$ {LOG_HOME}/${SERVER_NAME}.log" \t\t\t filePattern="$ {LOG_HOME}/${BACKUP_HOME}/debug/${BACK_FOLDER}/${SERVER_NAME}-%i.log${BACKUP_FILE_NAME_SUFFIX}"% 26gt; \t\t\t% 26lt; PatternLayout pattern="$ {PATTERN}" /% 26gt; \t\t\t% 26lt; Policies> % 26lt; SizeBasedTriggeringPolicy size="$ {EVERY_FILE_SIZE}" /% 26gt; % 26lt; TimeBasedTriggeringPolicy interval=" 1" modulate=" true" /% 26gt; % 26lt;/ Policies> \t\t\t% 26lt; Filters> \t\t\t\t% 26lt; ThresholdFilter level=" info" onMatch=" DENY" onMismatch=" NEUTRAL" /% 26gt; \t\t\t\t% 26lt; ThresholdFilter level=" debug" onMatch=" ACCEPT" onMismatch=" DENY" /% 26gt; \t\t\t% 26lt;/ Filters> \t\t\t% 26lt; CronTriggeringPolicy schedule="$ {SCHEDULE}"/% 26gt; \t\t\t% 26lt; DefaultRolloverStrategy max="$ {MAX}"% 26gt; \t\t\t\t% 26lt; Delete basePath="$ {LOG_HOME}" maxDepth="$ {MAXDEPTH}"% 26gt; \t\t\t\t\t% 26lt; IfFileName glob="$ {BACKUP_HOME}/debug/*/*.log*" /% 26gt; \t\t\t\t\t% 26lt; IfLastModified age="$ {AGE}" /% 26gt; \t\t\t\t% 26lt;/ Delete> \t\t\t% 26lt;/ DefaultRolloverStrategy> \t\t% 26lt;/ RollingFile> \t% 26lt;/ appenders> \t% 26lt;!-- Then define a logger. Only when a logger is defined and an appender is introduced will the appender take effect --% 26gt; \t% 26lt; loggers> % 26lt;!-- Reduce some debug logs --% 26gt;% 26lt; logger name=" org.apache.shiro" level=" INFO"/% 26gt; % 26lt; logger name=" org.springframework" level=" INFO"/% 26gt; % 26lt; logger name=" org.springframework.context" level=" INFO"/% 26gt; % 26lt; logger name=" org.springframework.beans" level=" INFO"/% 26gt; % 26lt; logger name=" com.baomidou.mybatisplus" level=" INFO"/% 26gt; % 26lt; logger name=" org.apache.ibatis.io" level=" INFO"/% 26gt; % 26lt; logger name=" org.apache.http" level=" INFO"/% 26gt; % 26lt; logger name=" io.lettuce" l


热门排行

最新文章

Powered by 世界滤芯新闻网 @2018 RSS地图 HTML地图

Copyright 365建站 © 2008-2021 华绿环保 版权所有