log4j (i)--log4j Introductory example

Source: Internet
Author: User

steps:
  1. Create a new Java project and import the log4j jar package;
  2. Create the Log4j.properties profile and set it in the SRC directory;
    1 # Set the global output level2Log4j.rootlogger=Error,stdout,file3 4 # Output logs above the error level to the console5log4j.appender.stdout=Org.apache.log4j.ConsoleAppender6log4j.appender.stdout.target=System.out7log4j.appender.stdout.layout=Org.apache.log4j.PatternLayout8Log4j.appender.stdout.layout.conversionpattern=%d{yyyy-mm-dd HH:mm:ss}%-5p%c{1}:%l-%m%N9 Ten # Output error level above log to E:\\test.log Onelog4j.appender.file=Org.apache.log4j.RollingFileAppender Alog4j.appender.file.file=E:\\test.log -Log4j.appender.file.maxfilesize=5MB -log4j.appender.file.maxbackupindex=10 thelog4j.appender.file.layout=Org.apache.log4j.PatternLayout -Log4j.appender.file.layout.conversionpattern=%d{yyyy-mm-dd Hh\:mm\:ss}%-5p%c{1}\:%l-%m%n
  3. Logging in Java code;
    1  PackageBasic;2 3 ImportOrg.apache.log4j.Logger;4 5  Public classLog4jtest {6 7     Private Static FinalLogger Logger = Logger.getlogger (log4jtest.class);8     9      Public Static voidMain (string[] args) {TenLogger.error ("This is debug message.")); One     } A}
  4. Output Result:
    Results of the console output:

    Results of the log file output:

log4j (i)--log4j Introductory example

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.