= "Org.apache.log4j.RollingFileAppender"> paramname= "File"value= "D:/output.log" />set Log output file path (including file name) - set whether new logs are appended to the original log when the service is restarted - paramname= "Append"value= "true" /> paramname= "Maxbackupindex"value= "Ten" /> Layoutclass= "Org.apache.log4j
Configuration information of Log4j. xml and Log4j. xml
Source code
1
Log4j. xml configuration
Value = "[% d {dd HH: mm: ss, SSS/} %-5 p] [% t] % c {2/}-% m % n"/>Value = "[% d {MMdd HH: mm: ss SSS/} %-5 p] [% t] % c {3/}-% m %
Add log4j to Web. xml and log4j to Web. xml
The configuration file is as follows. Web. xml
The log4jproperties file exists and is also configured in webxml. Why does it still r
When working with an XML file, you may experience a situation where the file contains sensitive data, and your favorite XML processing tool has a problem, such as a bug. You need to provide the vendor with a sample file that cause
log4j Configuration Sample
#定义根日志级别和输出端 (two outputs defined) Log4j.rootlogger=error,console,orclight #定义第一个输出端, output to console log4j.appender.console=
Org.apache.log4j.ConsoleAppender Log4j.appender.console.layout=org.apache.log4j.patternlayout log4j.appender.console.layout.conversionpattern=%d [%t]%-5p%c (%l)-%m%n #定时第二个输出端, output to a file with a maximum
configuration file
LOG4J supports two types of configuration file formats:
1. XML-formatted files
2. File in properties format
You can also configure the LOG4J environment in code without using a configuration
method % d {iso8601}, % d {absolute}, % d {relative}. Or use the iso8601dateformat, absolutetimedateformat, relativetimedateformat, and datetimedateformat of log4j.
% F Class Name of the class to which the output log information belongs
% L location where the log event is output, that is, the number of lines in the class where the statement that outputs the log information is located
% M output the specified information in the Code, such as the messa
Log library.ImportOrg.apache.log4j.Logger;ImportJava.io.*;Importjava.sql.SQLException;ImportJava.util.*; Public classlog4jexample{/*Get Actual class name to being printed on*/ StaticLogger log =Logger.getlogger (log4jexample.class. GetName ()); Public Static voidMain (string[] args)throwsioexception,sqlexception{Log.debug ("Hello This is a debug message"); Log.info ("Hello This is an info message"); }}Compile and run:Here are the steps to compile and run the above program. Be sure to set the
information can be output, such as the designated day level for info, then info, WARN, ERROR, fatal log can be output.
②appender: Defines the destination of the log message output, specifying where the log message should be exported, either a console, a file, or a network device.
③layout: Specifies the output format of the log message.
The log4j configuration file
the configuration file is obtained by combining the log4j configuration file with the project path; the configuration information is read; and then "log4j" is reset. appender. file. file value, which is the path of the log input,
WEB-INF/classes directory. When the log4j configuration file is no longer the default name, you need to load and provide parameters, such as "ropertyConfigurator. configure (props); // load log4j configuration information"
(2). configuration in Web. xml
Note: The above load-on-startup is set to 0 to load the Servlet w
The previous article on the log4j of the properties of the configuration, although the sense of difference is not very large, but the Log4j.properties configuration method can not use filter filter to limit the log level, another reason is Log4j.xml SQL statements can be placed in the Conversionpattern parameter of the Layout property when the database is inserted, and the log4j.properties configuration becomes more cumbersome . First, step1. Introdu
will make your application more flexible.LOG4J supports two configuration file formats, one in XML format and one in the properties format. Here's how to use the properties format as a configuration file:Example:Log4j.rootlogger=info, A1Log4j.appender.a1=org.apache.log4j.consoleappenderLog4j.appender.a1.layout=org.apache.log4j.patternlayoutLOG4J.APPENDER.A1.LAYOUT.CONVERSIONPATTERN=%-4R%-5p [%t] 7c%3x-%m%n
Configuration parameter Description:
(1). The output mode Appender generally has 5 kinds:
Org.apache.log4j.RollingFileAppender (scrolling file, automatic recording of the latest log)
Org.apache.log4j.ConsoleAppender (console)
Org.apache.log4j.FileAppender (file)
org.apache.log4j.DailyRollingFileAppender (generate one log
already contains the functions of Webapprootlistener.General configuration Type the following example: XML code
log4jrefreshinterval in Web. XML
Log4jrefreshinterval is 3000 to open a watchdog thread to scan for changes in configuration files every 3 seconds.
The ability to dynamically modify the Log4j.properties key, the container scans the log4j config
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.