1. Differentiate file output by log level
Some people are accustomed to log information level output to different names of files, such as Info.log,error.log,warn.log, in the LOG4J2 can be configured by the filters to implement.
It is assumed that the information output to the Info.log,warn and error levels of info and the following levels is output to the error.log,fatal level to Fatal.log, and the configuration file is as follows:
[Java] View plain copy print? <configuration status= "WARN" monitorinterval= "> < properties> <property name= "LOG_HOME" >D:/logs</property> </properties> <Appenders> <console name = "Console" target= "System_out" > <patternlayout pattern= "%d{hh:mm:ss. sss} [%t] %-5level %logger{36} - %msg%n " /> </Console> <rollingrandomaccessfile name= "Infofile" filename= "${log_home}/info.log" filepattern= "${log_home}/$${date:yyyy-mm}/info-%d{yyyy-mm-dd}-%i.log" > <Filters> <thresholdfilter level= " Warn " onmatch=" DENY " onmismatch=" NEUTRAL " /> <thresholdfilter level= "Trace" Onmatch= "ACCEPT" onmismatch= "DENY" /> </Filters> <patternlayout pattern= "%date{yyyy-mm-dd hh:mm:ss. sss} %level [%thread][%file:%line] - %msg%n " /> <Policies> <TimeBasedTriggeringPolicy /> <sizebasedtriggeringpolicy size= "10 MB " /> </ policies> < defaultrolloverstrategy max= " /> " </RollingRandomAccessFile> <rollingrandomaccessfile name= "ErrorFile" filename= "${log_home}/error.log" filepattern= "${log_home}/$${date:yyyy-mm}/error-%d{yyyy-mm-dd}-% I.log "> <Filters> <thresholdfilter level= "Fatal" onmatch= "DENY" onmismatch= "NEUTRAL" /> < Thresholdfilter level= "Warn" onmatch= "ACCEPT" onmismatch= "DENY" /> </Filters> <patternlayout pattern= "%date{yyyy-MM-dd hh:mm:ss. Sss} %level&nBsp [%thread] [%file:%line] - %msg%n] /> <Policies> <TimeBasedTriggeringPolicy /> <sizebasedtriggeringpolicy size= "10&NBSP;MB" /> </Policies> <defaultrolloverstrategy max= " /> " </RollingRandomAccessFile> <rollingrandomaccessfile name= "FatalFile" &NBSP; filename= "${LOG_HOME}/fatal.log" filepattern= "${LOG_HOME}/$${date : Yyyy-mm}/fatal-%d{yyyy-mm-dd}-%i.log "> <Filters> <thresholdfilter level= "Fatal" onmatch= "ACCEPT" Onmismatch= "DENY" />