Many diaosi think that log4j is not easy to use because it is not output to the IDE console. Haha, it is actually a disaster caused by configuration. The following describes how to configure log4j to the console step by step,
I believe that log4j's output level and output mode are all known. I will not talk about it here. Let's just look at the code comment:
# All, TRACE, DEBUG, INFO, WARN, ERROR, FITAL, OFF
# Global project log Configuration
Log4j. rootLogger = ERROR
# All logs under the specified package (only logs under the project com package are output)
Log4j.logger.com = DEBUG, yin, dailly_rolling_file
# The specified output level is not managed globally
Log4j.additivity.com = false
# Output to the console
Log4j. appender. yin = org. apache. log4j. leleappender
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 the size of the scroll 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.2cto.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 objects by date
Log4j. appender. dailly_rolling_file = org. apache. log4j. DailyRollingFileAppender
Log4j. appender. dailly_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