configuration file

configuration file

 

 Use of log4j

 1. Import log4j.jar

 2. Create log4j, propetites configuration files under the same level of src directory

 3. In the class that needs to print the log, get a log object through Logger.getLogger(); and pass the parameter into Demo03TestLog.class (object of this class)

 4. Use the log object to call different levels of print statements to output the statement

 

 log.debug("打印debug");

 log.info("print info");

 log.warn("打印warn");

 log.error("打印error");

 

 

 

 

 

#[Specify log output destination for Appender]

 

#org.apache.log4j.ConsoleAppender (console),

#org.apache.log4j.FileAppender(file),

#org.apache.log4j.DailyRollingFileAppender (generates a log file every day),

#org.apache.log4j.RollingFileAppender (a new file is generated when the file size reaches the specified size)

log4j.appender.A=org.apache.log4j.ConsoleAppender

 

# Set the statement to print to the console.

 System.out/System.err

log4j.appender.A.Target=System.err(orr黑 /err红)

 

 

# Which layout to use for log display:

# org.apache.log4j.HTMLLayout (layout in HTML table),

# org.apache.log4j.PatternLayout (the layout pattern can be flexibly specified),

# org.apache.log4j.SimpleLayout (contains the level and information string of log information),

#org.apache.log4j.TTCCLayout (including log generation time, thread, category, etc.)

log4j.appender.A.layout=org.apache.log4j.SimpleLayou

log4j.appender.logfile=org.apache.log4j.FileAppender

 

# Set the address of the file

 

log4j.appender.logfile.File=mylog.log

log4j.appender.logfile.layout=org.apache.log4j.PatternLayout

 

 

# Set the style for PatternLayout.

# %m print the message specified in the code

# %p output priority, ie DEBUG, INFO, WARN, ERROR, FATAL

# %r Output the number of milliseconds it took to output the log information since the application was started

# %c The category to which the output belongs, usually the full name of the category

# %t output the name of the thread that generated the log event

# %n output a carriage return line feed, "\r\n" for Windows platform, "\n" for Unix platform

# %d Output the date or time of the log time point, the default format is ISO8601, you can also specify the format after it, for example: %d{yyy MMM dd HH:mm:ss , SSS}, the output is similar to: October 18, 2002 Sun 22:10:28, 921

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324688119&siteId=291194637