Log4j.properties configuration details and examples-all tests pass

Source: Internet
Author: User
Tags html form print format log4j
Recently used log4j write log when found on the Internet are all the same, write a good why not all, write a full point of no format, look tired. Here the online collection of the collation, and all on the machine to test successfully. I don't think that's a good document.
################################################################################
#① configures the root logger with the following syntax:
#
#log4j. Rootlogger =[level],appendername,appendername2,...
#level是日志记录的优先级, divided into Off,trace,debug,info,warn,error,fatal,all
# #Log4j建议只使用四个级别, priority from low to High is debug,info,warn,error
#通过在这里定义的级别, you can control the switch to the corresponding level of log information in your application
#比如在这里定义了INFO级别, all debug-level log information in the application will not be printed
#appenderName就是指定日志信息输出到哪个地方. Multiple output purposes can be specified at the same time
################################################################################
################################################################################
#② Configuration log information output destination Appender, its syntax is:
#
#log4j. Appender.appendername =fully.qualified.name.of.appender.class
#log4j. Appender.appenderName.optionN =valuen
#
#Log4j提供的appender有以下几种:
#1) Org.apache.log4j.ConsoleAppender (output to console)
#2) Org.apache.log4j.FileAppender (output to file)
#3) org.apache.log4j.DailyRollingFileAppender (Generate a log file every day)
#4) Org.apache.log4j.RollingFileAppender (a new file is generated when the file size reaches a specified size)
#5) Org.apache.log4j.WriterAppender (send log information to any specified place in streaming format)
#
#1) consoleappender Option Properties
#-threshold = DEBUG: Specifies the lowest level of output for log messages
#-immediateflush = true: The default value is true, all messages are immediately exported
#-target = System.err: Default value System.out, output to console (Err is red, out is black)
#
#2) fileappender Option Properties
#-threshold = INFO: Specifies the lowest level of output for log messages
#-immediateflush = true: The default value is true, all messages are immediately exported
#-file = C:\log4j.log: Specify message output to C:\log4j.log file
#-append = false: Default value True, append message to specified file, FALSE to overwrite the specified file contents
#-encoding = UTF-8: You can specify a file encoding format
#
#3) dailyrollingfileappender Option Properties
#-threshold = WARN: Specifies the lowest level of output for log messages
#-immediateflush = true: The default value is true and all messages are immediately exported
#-file =c:\log4j.log: Specify message output to C:\log4j.log file
#-append= false: Default value TRUE to append messages to the specified file, FALSE to overwrite the specified file contents
#-datepattern= '. ' YYYY-WW: Scrolls the file once a week, that is, a new file is generated each week. You can also use the following parameters:
#              '.' YYYY-MM: Monthly
#              '.' YYYY-WW: Weekly
#              '.' YYYY-MM-DD: Every day
#              '.' Yyyy-mm-dd-a: two times a day
#              '.' YYYY-MM-DD-HH: Per hour
#              '.' YYYY-MM-DD-HH-MM: Per minute
#-encoding = UTF-8: You can specify a file encoding format
#
#4) rollingfileappender Option Properties
#-threshold = ERROR: Specifies the lowest level of output for log messages
#-immediateflush = true: The default value is true and all messages are immediately exported
#-file =c:/log4j.log: Specify message output to C:/log4j.log file
#-append= false: Default value TRUE to append messages to the specified file, FALSE to overwrite the specified file contents
#-maxfilesize = 100KB: suffix can be kb,mb,gb. When the log file reaches that size, it will scroll automatically. For example: Log4j.log.1
#-maxbackupindex = 2: Specifies the maximum number of scrolling files that can be produced
#-encoding = UTF-8: You can specify a file encoding format
################################################################################
################################################################################
#③ configures the format (layout) of the log information, and its syntax is:
#
#log4j. Appender.appendername.layout=fully.qualified.name.of.layout.class
#log4j. appender.appendername.layout.optionn= Valuen
#
The layout provided by the #Log4j are available in the following ways:
#5) org.apache.log4j.HTMLLayout (layout in HTML form)
#6) Org.apache.log4j.PatternLayout (flexibility to specify layout patterns)
#7) Org.apache.log4j.SimpleLayout (level and information string that contains log information)
#8) Org.apache.log4j.TTCCLayout (contains information about the time, thread, category, and so on that the log was generated)
#9) org.apache.log4j.xml.XMLLayout (layout in XML)
#
#5) htmllayout Option Properties
#-locationinfo = TRUE: Default value False, output Java file name and line number
#-title=struts LOG Message: Default value Log4jlog Messages
#
#6) patternlayout Option Properties
#-conversionpattern =%m%n: Format the specified message (with the parameter meaning below)
#
#9) xmllayout Option Properties
#-locationinfo = TRUE: Default value False, output Java file name and line number
#
#Log4J format the log information using a print format similar to the printf function in C, printing 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 it takes to boot to output the log information
The class of the #%c output, which is usually the full name of the class in which it belongs
#%t output The name of the thread that generated the log event
#%n output a carriage return line feed, Windows platform "\ r \ n", UNIX platform "\ n"
#%d the date or time of the output log point in time, the default format is ISO8601, or you can specify the format later
# such as:%D{YYYY year mm month DD Day HH:MM:SS,SSS}, output similar: January 05, 2012 22:10:28,921
#%l where the output log event occurs, including the class name, the thread that occurred, and the number of lines in the code
# such as: Testlog.main (TESTLOG.JAVA:10)
#%f the name of the file where the output log message was generated
#%l the line number in the output code
#%x output is associated with the current line threads relative NDC (nested diagnostic environment), as in the application of Javaservlets multi-client multithreading
#%% output A "%" character
#
# You can control the minimum width, the maximum width, and the alignment of text by adding modifiers between% and pattern characters. Such as:
#%5c: Output category name, minimum width is 5,category<5, right justified by default
#%-5c: Output category name, minimum width is 5,category<5, "-" number specifies left alignment, there are spaces
#%.5c: Output category name, the maximum width is 5,category>5, will be left out of the characters to intercept, &LT;5 will not have spaces
#%20.30c:category name <20 fill space, and right aligned, >30 characters, from the left hand sold out characters cut off
################################################################################
################################################################################
#④ Specifies the output-specific level of a particular package
#log4j. Logger.org.springframework=debug
################################################################################

#OFF, Systemout,logfile,logdailyfile,logrollingfile,logmail,logdb,all.
Log4j.rootlogger=all,systemout,logfile,logdailyfile,logrollingfile,logmail,logdb

#

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.