Java uses log4j

Source: Internet
Author: User

1. Introduction of the JAR package

Log4j-1.2.13.jar

2.SRC Setup configuration file: Log4j.properties

  #不 +all, write only the latter Loglog4j.rootlogger =all,systemout,logrollingfile #输出到控制台 Log4j.appender.systemOut = Org.apache.log4j.ConsoleAppender Log4j.appender.systemOut.layout = Org.apache.log4j.PatternLayout # "%-5p": Message type (DEBUG? INFO? ), left to it, 5 characters # "%l": that file that method which line output log# "%n": NewLine # "%m": Log Message Log4j.appender.systemOut.layout.ConversionPattern = [%-5p][%- 22d{yyyy/mm/dd HH:mm:ss. sss}][%l]%n%m%n# threshold (Log level: Debug,info,error,warn) Log4j.appender.systemOut.Threshold = debug# setting file size output to file Log4j.appender.logRollingFile = Org.apache.log4j.RollingFileAppender Log4j.appender.logRollingFile.layout = Org.apache.log4j.PatternLayout Log4j.appender.logRollingFile.layout.ConversionPattern =%m% Nlog4j.appender.logRollingFile.Threshold = DEBUG Log4j.appender.logRollingFile.File = c:/log/ahlog.txt Log4j.appender.logRollingFile.MaxFileSize = 1MB Log4j.appender.logRollingFile.MaxBackupIndex = ten  
Reference:
http://blog.csdn.net/dr_guo/article/details/50718063 "Log4j.properties configuration detailed and examples
"
3. Write the Java test file:
Import Org.apache.log4j.Logger;  Public class testlog4j {    static Logger log = Logger.getlogger (testlog4j.  Class. GetName ());      Public Static void Main (string[] args) {        log.debug ("AH Debug");        Log.info ("AH info");        Log.error ("AH error");        Log.warn ("AH warn");}    }

Java uses log4j

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.