I. Introduction of LOG4JThe log4j has three main components: loggers (Logger), appenders (output source), and layouts (layout). This can be simply understood as the log category, where the logs are to be exported and how the logs are exported. The combined use of these three components makes it easy to record the type and level of information, and to control the style and location of the log output at run t
: "Org.apache.elathen.ClassName",%c{2} will output elathen. ClassName)
%d output log time its format is%d{yyyy-mm-dd hh:mm:ss,sss}, you can specify the format such as%d{hh:mm:ss}
%l output Log event occurrence location, including class name, occurrence thread , the number of lines in the code
%n
%m Output Code specify information, such as info ("message"), output message
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
method is to use a subclass to overwrite the Setfile method, which is called when the log4j reads the configuration file to generate Appender, and the incoming is the matchingThe path in the file so that I can add a root path to the path in front of my own mind. This method can be used to configure the Log4j.appender.A1.File
In the whole web system, in order to unify the use of log management, it is necessary to load the log4j configuration file when the system is started, in order to ensure that the format of the later use of log4j is consistent, easy to track and solve the problem. So, how to load the log4j configuration
The log4j configuration file (Configuration file) is used to set the level, the repository, and the layout of the logger, and it can be set in key=value format or in XML format information. By configuring, you can create a log4j running environment. The
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
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 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
When deploying two or more projects under Tomcat, it is best to define the Webapprootkey parameter in the Web. xml file and, if undefined, default to "Webapp.root", as follows: Application Path - Context-param> Param-name>WebapprootkeyParam-name> Param-value>Webapp.rootParam-value> Context-param> Best newspaper The parameter values for each item are different to avoid conflict
Transferred from: http://blog.csdn.net/arvin_qx/article/details/6829873When deploying two or more projects under Tomcat, it is best to define the Webapprootkey parameter in the Web. xml file and, if undefined, default to "Webapp.root", as follows:It is best to ensure that the parameter values for each item are different to avoid conflicting items:Web App root system property already set to different value:
When deploying two or more projects under Tomcat, it is best to define the Webapprootkey parameter in the Web. xml file, which, if undefined, defaults to "Webapp.root", as follows:
Best newspaper The parameter values for each item are different to avoid conflicting items
Severity: Exception sending context initialized event to listener instance of class Org.springframework.web.util.Log4jConfigLis TenerJava
log4j.appender.r.maxfilesize=100kb# Save a backup fileLog4j.appender.r.maxbackupindex=1 3. log4j log File Save location Take Dailyrollingfileappender as an example: Suppose a log file per day the following settings are available: Log4j.appender.a1=org.apache.log4j.dailyrollingfileappender Log4j.appender.a1.
profile path.
Set Value VM System variables:Simply, by setting the value of the VM system variable log4j.configuration to the configuration file path before getting the Logmanager initialization value, you can achieve the purpose:
static {
String Customizedpath = "Log/log4j.xml";
System.setproperty ("Log4j.configuration", Customizedpath);
Logger = Logmanager.getlogger (Log4jonetest.class);
}
propertyconfigurator or Domconfigurator:Domcon
());// Initialize global variablesPublic void init () throws ServletException {// Use web. xml to Dynamically Retrieve the configuration fileString prefix = getServletContext (). getRealPath ("/");String file = getInitParameter ("log4j-init-file ");// If the corresponding configuration
(log4jlocation )){ Propertyconfigurator. Configure (root + log4jlocation ); } } } 2. Load the servlet in Web. xml 3. The relative path can be used in log4j. properties as follows: # Rlogfile Log4j. appender. rlogfile = org. Apache. log4j. rollingfileappender
, Log4j.appender.r.layout.conversionpattern=%d-[ts]%p%t%c-%m%n
9, Log4j.logger.com.johnny=debug
Customize the log level in each package, specifying that all classes under the Com.johnny package have a level of debug.
Second, loading their own configuration fileslog4j the Log4j.properties file under the default load Classpath, you need to use Domconfigurator.configure when customizing the properties file
root path to the path in front of my own mind. This method can be used to configure the Log4j.appender.A1.File property with relative paths freely in log4j.properties to determine the generated log relative to the Web application root
The location of the directory.
The second method is to set the log path relative to the ${catalina.home} by using the environment variables already existing in the server VM
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.