### set Log Levels ###
Log4j.rootlogger = Debug, stdout
#################################### Output to console ############################################
Log4j.appender.stdout = Org.apache.log4j.ConsoleAppender
Log4j.appender.stdout.Target = System.out
All classes below the #定义com. edu package are of debug
log4j.logger.com.edu =debug
Log4j.appender.stdout.layout = Org.apache.log4j.PatternLayout
Log4j.appender.stdout.layout.ConversionPattern =%d{yyyy-mm-dd hh:mm SS}%5p%c:%l-%m%n
#################################### Save exception information to a separate file ##################################
LOG4J.APPENDER.E = Org.apache.log4j.DailyRollingFileAppender
Log4j.appender.e.file = Logs/error.log
# # Exception Log file name
Log4j.appender.e.append = True
Log4j.appender.e.threshold = ERROR
# # Only logs above the error level are OUTPUT!!!
Log4j.appender.e.layout = Org.apache.log4j.PatternLayout
Log4j.appender.e.layout.conversionpattern =%-d{yyyy-mm-dd HH:mm:ss} [%t:%r]-[%p]%m%n
############################################################################################
#log4j. logger.com. Neusoft =debug
The level of all classes under the #指定com. Neusoft package is Debug.
############################################################################################
################################## #Appender输出目的地 ##########################################
# Org.apache.log4j.ConsoleAppender (console),
# org.apache.log4j.FileAppender (file),
# org.apache.log4j.DailyRollingFileAppender (Generate a log file every day),
# Org.apache.log4j.RollingFileAppender (a new file is generated when the file size reaches the specified size),
# log4j.appender.mylog.maxfilesize=100kb: The suffix can be kb, MB, or GB. When the log file reaches that size, it scrolls automatically, moving the original content to the Mylog.log.1 file.
# log4j.appender.mylog.maxbackupindex=2: Specifies the maximum number of scrolling files that can be produced.
# Org.apache.log4j.WriterAppender (send log information to any specified place in streaming format)
##############################################################################################
################################## #Log4j提供的layout有以下几种 #################################
# org.apache.log4j.HTMLLayout (layout in HTML form),
# org.apache.log4j.PatternLayout (You can specify layout patterns flexibly),
# Org.apache.log4j.SimpleLayout (The level and information string that contains the log information),
# org.apache.log4j.TTCCLayout (contains information about the time, thread, category, and so on that the log was generated)
#############################################################################################
#################################### #日志输出格式 #############################################
#-x Number: X information output when left aligned;
#%p: Output log information priority, i.e. Debug,info,warn,error,fatal,
#%d: the date or time of the output log point-in-time, the default format is ISO8601, or the format can be specified thereafter, for example:%d{yyy MMM dd hh:mm:ss,sss}, Output is similar: October 18, 2002 22:10:28,921
#%r: The number of milliseconds to output from the application boot to the output of this log information
#%c: The class that the output log information belongs to, usually the full name of the class in which it is located
#%t: Output The name of the thread that generated the log event
#%l: The location of the output log event, equivalent to the combination of%c.%m (%f:%l), including the class name, the thread that occurred, and the number of lines in the code. Example: Testlog4.main (testlog4.java:10)
#%x: The output is associated with the current line threads relative NDC (nested diagnostic environment), especially in multiple client multi-threaded applications such as Java Servlets.
#%%: Output A '% ' character
#%F: The name of the file where the output log message was generated
#%l: line number in the output code
#%m: Output code specified in the message, the resulting log specific information
#%n: Output a carriage return line break, Windows platform is "/r/n", UNIX platform is "/n" Output log message Wrapping
# You can control the minimum width, the maximum width, and the alignment of text by adding modifiers between% and pattern characters. Such as:
# 1)%20c: Specifies the name of the output category, the minimum width is 20, and if the category name is less than 20, the default is right-aligned.
# 2)%-20c: Specifies the name of the output category, the minimum width is 20, and if the category name is less than 20, the "-" number specifies left-aligned.
# 3)%.30c: Specifies the name of the output category, the maximum width is 30, if the category name is greater than 30, will be the left more characters truncated, but less than 30 words will not have spaces.
# 4%20.30c: If the name of the category is less than 20, the space is filled and right-aligned, and if its name is longer than 30 characters, it is truncated from the character that is farther from the left.
#############################################################################################
######################################### #使用方法 ###########################################
# public class Log4jtest {
# public static void Main (string[] args) {
# propertyconfigurator.configure ("Src/log4j.properties");
# Logger log = Logger.getlogger (Log4jtest.class);
# log.fatal ("Fatal message!");
# Log.error ("Errors message!");
# Log.warn ("This are my warn message!");
# Log.info ("This is a info message!");
# Log.debug ("This is a debug message!");
# }
# }
#############################################################################################
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.