Alibabacloud.com offers a wide variety of articles about spring log4j configuration example, easily find your spring log4j configuration example information here online.
the time, thread, category, and so on that the log produced) Log4j.appender.a.layout=Org.apache.log4j.SimpleLayoutlog4j.appender.logfile=org.apache.log4j.fileappender# The address of the settings file Log4j.appender.logfile.File=Mylog.loglog4j.appender.logfile.layout=org.apache.log4j.patternlayout# sets the style for patternlayout. #%the message specified in the M output code #%P-Output priority, i.e. Debug,info,warn,error,fatal #%r output The number of milliseconds to output the log informatio
differ greatly from reading the normal configuration file. Get some log4j property values for the user configuration, and call the method that you want to set for the Log4j property.Think of Log4j.properties as a struts.xml or a hibernate-cfg.xml. But the difference is that unlike struts and hibernate,
Output The name of the thread that generated the log event %n Output a carriage return line break, the Windows platform is "/r/n", and the UNIX platform is "/n" %d output log point-in-time date or time, the default format is ISO8601, you can also specify the format after, such as:%d{yyy MMM dd HH:mm:ss, SSS}, output similar: October 18, 2002 22:10:28, 921 %l The location where the output log event occurs, including the class name, the thread that occurred, and the number of lines in the code
operations that log records are processed.Its syntax is:Log4j.rootlogger = [level], Appendername, Appendername, ...Level is the priority of logging, which is divided into off, FATAL, ERROR, WARN, INFO, DEBUG, all, or your own defined levels. LOG4J recommends using only four levels. Priority levels from high to low are error, WARN, INFO, DEBUG, respectively. By the level defined here. A switch that you can control to the corresponding level of log inf
Og4j Advanced Tips-Location of dynamic configuration log output files
The usual use of log4j is to write the output file directly to death in its configuration file (XML or properties), which in many cases is very simple and effective. The disadvantage of this is that if you want this Web application to run, you have to modify the
dimension of the Num class name output (such as: "Org.apache.elathen.ClassName",%c{2} will output elathen. ClassName)
%d output log time in the format of%d{yyyy-mm-dd hh:mm:ss,sss}, you can specify a format such as%d{hh:mm:ss}
%l output Log event occurrence location, including class name, occurrence thread, number of lines in code
%n line break
%m output code to specify information, such as info ("message"), output message
%p output priority, that is, FATAL, ERROR, etc.
%r output the number of
The log4j configuration file is used to set the level, the repository, and the layout of the logger, which can be set in key=value format or in XML format.By configuration, you can create a running environment for log4j.1. The basic format of the configuration file
name and other information, using log4j default initialization process to resolve and configure;4 configuration in the file, through the application server configuration to pass the file name and other information, using a special servlet to complete the configuration.
3. Set the log output level for different appende
(Action) startup level to 3 or 2, preferably by putting the log4j boot before struts.
In addition, the log4j is enhanced in the Spring framework:Instead of writing a servlet to start log4j, you can use spring's log4jconfiglistener listener directly. There are several benefits to doing this, and the biggest benefit is
Advantages of 1.LOG4JLog4j is an open source project for Apache, by using log4j, we can control the delivery of log information, we can control the output format of each log, and by defining the level of each log information, we can control the log generation process more carefully. Most interesting of all, these can be configured flexibly with a single configuration file without the need to modify the appl
Create a Logger object first
private static final Logger Logger = Loggerfactory.getlogger (Logincontroller.class);
Then you can use it in the method.
Logger.info ("index----------------");
Logger.error ("index----------------");
Logger.warn ("index----------------");
configuration file Explanation
1. Configure the root logger, whose syntax is:
Log4j.rootlogger = [level], Appendername, Appendername, ...
Where level is the pr
configures the LOG4J environment with the following syntax: /** Basicconfigurator.configure (); Automatically and quickly use the default log4j environment. * Propertyconfigurator.configure (* "D:\\project\\eclipse\\log4j\\src\\log4j.properties"): * Read the properties file using Java The configuration file tha
generated the log event
%n output a carriage return line feed, Windows platform "\ r \ n", UNIX platform "\ n"
%d output log point-in-time date or time, the default format is ISO8601, you can also specify the format after, such as:%d{yyy MMM dd HH:mm:ss, SSS}, output similar: October 18, 2002 22:10:28, 921
%l the location where the output log event occurs, including the class name, the thread that occurred, and the number of lines in the code. Example
your application. For example, if the info level is defined here, only if it is equal to or above that level, the log information for all debug levels in the application will not be printed. All: Print all logs, off: Turns off all log output. Appendername is where you specify where the log information is exported. Multiple output destinations can be specified at the same time.②, configuration log informati
When using log4j to print the application log, a colleague asked me if the different level of the same logger log could be output to a different file? This one... I told him. Of course, in our production environment using log4j has always been all logger error above level log input to the error log file, convenient system monitoring.In fact, this is easy to achieve, we are to add 2 appender,appender in logg
The default log framework provided by hibernate3 is slf4j. The SLF of hibernate3 is only a log interface, while the default log framework provided by hibernate3 is rarely used by companies or projects in actual development, here we record a log framework that uses log4j to replace the implementation of the slf4j log framework. The specific configuration and implementation are as follows:
I. added the
: Dynamic change record level and policy and load in the Web, that is, modify log4j.properties, do not need to restart Web applications, which need to be set in the Web.xml.1 The log file in/web-inf/logs/without the need to write an absolute path.2. Log4j.properties can be put together with other properties in/web-inf/, not class-path.First, we need to set up a web.xml
The second part is the key to dynamically modifying the log4j.properties, which scans the
The three main components of the log4j configuration file are:Logger,appender and layout, respectively, log type, log output destination, log output format.Log4j.rootlogger = [Level],appendername, Appendername, ...(Level is the error, Appendername is the output destination, this example is set to MyLog, you can define more than one) level priority is fatal, ERROR
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.