Many people think that log4j is difficult to use because it does not output to the IDE console. Haha, in fact, it is all caused by the configuration. Let’s see how I configured it to the console step by step. I believe that log4j’s output level and output mode are We all know it, so I won’t go into details here, just look at the code comments:
# All,TRACE,DEBUG,INFO,WARN,ERROR,FITAL,OFF
#Global project log configuration
log4j.rootLogger=ERROR
#All logs under the specified package (only output logs under the project com package)
log4j.logger.com=DEBUG,yin,dailly_rolling_file
#The specified output level is not globally managed
log4j.additivity.com=false
#Output to console
log4j.appender.yin = org.apache.log4j.ConsoleAppender
log4j.appender.yin.layout = org.apache.log4j.PatternLayout
log4j.appender.yin.layout.ConversionPattern = %n%d [%p] [%m] [%c] %M()[%L] %n
# Output to file
log4j.appender.file = org.apache.log4j.FileAppender
log4j.appender.file.File = C/://logs//log.log
log4j.appenile.file.Append = true
log4j.appender.file.layout = org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern = %-d{yyyy-MM-dd HH/:mm/:ss,SSS} [%c]-[%p] %m%n
#Output to size rolling file (100 indicates the number of backup files)
log4j.appender.rolling_file = org.apache.log4j.RollingFileAppender
log4j.appender.rolling_file.Threshold = ERROR
log4j.appender.rolling_file.File = C/://logs//log_rolling.log
log4j.appenile.rolling_file.Append = true www.VeVB.COm
log4j.appenile.rolling_file.MaxFileSize = 10KB
log4j.appenile.rolling_file.MaxBackupIndex = 100
log4j.appender.rolling_file.layout = org.apache.log4j.PatternLayout
log4j.appender.rolling_file.layout.ConversionPattern = %-d{yyyy-MM-dd HH/:mm/:ss,SSS} [%c]-[%p] %m%n
# Output to rolling file by date
log4j.appender.dailly_rolling_file = org.apache.log4j.DailyRollingFileAppender
log4j.appender.daily_rolling_file.File = C/://logs//log_daily_rolling.log
log4j.appender.dailly_rolling_file.DatePattern = .yyyy-MM-dd
log4j.appender.dailly_rolling_file.layout=org.apache.log4j.PatternLayout
log4j.appender.dailly_rolling_file.layout.ConversionPattern=%-d{yyyy-MM-dd HH/:mm/:ss,SSS} [%c]-[%p] %m%n