Log4j.properties detailed

Source: Internet
Author: User

Prefacelog4j is actually a very common and commonly used logging tool for Apache. Although has been used, but did not really write, yesterday and friends to discuss the log, so today will log4j grammar or something to see again. Today, I would like to share with you the most commonly used log4j.properties and log4j.xml.

The Chase 1. Configuration Log4j.properties is one of the most commonly used configuration files, it is simple and convenient to use, we first look at its configuration:
<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" ># set the root log level to INFO, file output to two locations, ErrorFile and Welcomefile.log4j.rootlogger=info, errorfile,welcomefile# The output of the ErrorFile is set to console output, and Welcomefile is output to a file named Welcome.log. log4j.appender.errorfile= org.apache.log4j.consoleappenderlog4j.appender.welcomefile= org.apache.log4j.rollingfileappenderlog4j.appender.welcomefile.file=welcome.log# Sets the output mode of the ErrorFile and displays the information log4j.appender.errorfile.layout= ORG.APACHE.LOG4J.PATTERNLAYOUTLOG4J.APPENDER.ERRORFILE.LAYOUT.CONVERSIONPATTERN=[QC]%p [%t]%C.%M (%L) | %m%nlog4j.appender.welcomefile.layout= ORG.APACHE.LOG4J.PATTERNLAYOUTLOG4J.APPENDER.WELCOMEFILE.LAYOUT.CONVERSIONPATTERN=[QC]%p [%t]%C.%M (%L) | %m%n# set the log level under the Com.dan.test package to DEBUG and output to the Welcome.log file Log4j.logger.com.dan.test=debug, welcomefile</span>



2. Detailed ConfigurationThe intent of each setting has been explained in the small section configuration file above, and I'll explain it in more detail below:1) log4j.rootlogger=info, Errorfile,welcomefile
This sentence outputs the log information of level info to both destinations ErrorFile and welcomefile ,welcomefile and welcomefile The definition in the following code, can be arbitrarily named. Level can be divided into off, FATAL, error, WARN, INFO, DEBUG, all, if the configuration off does not play any information, if configured as info so only display info, WARN, error log information, and DEBUG information will not be displayed.
2) Log4j.appender.errorfile=org.apache.log4j.consoleappender
This sentence defines what type of output is named ErrorFile , which can beOrg.apache.log4j.ConsoleAppender (console),org.apache.log4j.FileAppender (file),org.apache.log4j.DailyRollingFileAppender (generates a log file every day),Org.apache.log4j.RollingFileAppender (creates a new file when the file size reaches the specified size)Org.apache.log4j.WriterAppender (send log information in stream format to any specified location)
3) Log4j.appender. errorfile. Layout=org.apache.log4j.patternlayout
This sentence is the type of layout that defines the output named stdout, which can beorg.apache.log4j.HTMLLayout (Layout in HTML table Form),Org.apache.log4j.PatternLayout (flexibility to specify layout mode),Org.apache.log4j.SimpleLayout (contains the level of log information and the information string),Org.apache.log4j.TTCCLayout (contains information about the time, thread, category, etc.) of the log
4) log4j.appender.stdout.layout.conversionpattern= [QC]%p [%t]%c.%m (%l) | %m%n
If you use the pattern layout to specify the exact format of the printed information Conversionpattern, print the parameters as follows:%m The message specified in the output code%p output priority, i.e. Debug,info,warn,error,fatal%r Output The number of milliseconds that the log information is consumed from the application boot to output%c output belongs to the class, which is usually the full name of the class%t Output The name of the thread that generated the log event%n output A carriage return newline character, Windows platform is "RN", UNIX platform is "n"%d the date or time of the output log time, the default format is ISO8601, can also be specified after the format, such as:%d{yyyy MMM dd hh:mm:ss,sss}, output similar: April 30, 2015 12:10:28,921%l where the output log event occurs, including the class name, the thread that occurred, and the number of rows in the code. [QC] is the beginning of the log information, can be any character, generally referred to as the project abbreviation. the output information[TS] DEBUG [main] com.dan.test.testclass-debug msg
5) log4j.appender.welcomefile.file=welcome.log
This sentence is a file named Welcomethat defines the output named welcomefile . Log can be modified by itself.
6) Log4j.logger.com.dan.test=debug, Welcomefile
specifies that all classes under the com.dan.testT package are rated as debug log information output to welcomefile The specified file, can putcom.dan.testChange the package name that you used for your project.
Summary:The log plays an important role in our project, helps us to analyze the problem, and if we can flexibly configure the log, it will greatly improve our efficiency in solving the problem.

Log4j.properties detailed

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.