Log4j detailed configuration, no regrets

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.