当前位置:网站首页>Log4j output log information to file

Log4j output log information to file

2022-04-23 16:42:00 A hundred nights

Log4j It's made up of three important components : Priority of log information , The output destination of log information , The output format of log information . The priority of log information varies from high to low ERROR、WARN、INFO、DEBUG, Used to specify the importance of this log information ; The output destination of the log information specifies whether the log will be printed to the console or to a file ; The output format controls the display of log information .

log4j.properties Output ERROR Level log to console and file .
log4j.rootLogger: Specify log level and output source , Separated by commas .
org.apache.log4j.ConsoleAppender: Specify output to console .
org.apache.log4j.ailyRollingFileAppender: Specify output to file .
log4j.appender.X.File: Specify the output file path .
log4j.appender.X.Append: Specifies that the log data is input into the file in the form of append , The default is false, Designated as true.
log4j.appender.X.Threshold: Specify what log level data to import into the file DEBUG,ERROR.
log4j.appender.X.layout = org.apache.log4j.PatternLayout
log4j.appender.X.layout.ConversionPattern: Specify the presentation form of log data .

###  Set up ###
###  Set up ###
log4j.rootLogger = debug,D,E
###  Output DEBUG  Log above level to =E://logs/error.log ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = E://logs/log.log
log4j.appender.D.Append = true
log4j.appender.D.Threshold = DEBUG 
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %-d{
    yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n

###  Output ERROR  Log above level to =E://logs/error.log ###
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File =E://logs/error.log 
log4j.appender.E.Append = true
log4j.appender.E.Threshold = ERROR 
log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern = %-d{
    yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n

版权声明
本文为[A hundred nights]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231401521233.html