Http://blog.csdn.net/wiwipetter/archive/2009/07/30/4390579.aspx1. log4j output multiple custom log filesThe powerful function of log4j is unquestionable, but in practical application it is unavoidable to have a function to output independent log files, how to separate the required content from the original log, and form a separate log file. In fact, as long as the existing
The log4j jar package contains the preference default configuration, and the user can specify their own configuration by Log4j.xml or log4j.properties. XML is preferred over properties. Note also that Java reads the properties file only by means of the = sign to split the key-value pairs, so the # comment cannot be placed on the same line as the key-value pair de
First, log4j configuration
The first step: Join Log4j-1.2.8.jar to Lib.
Step two: Establish the log4j.properties under the classpath. The contents are as follows:
If you put it under SRC, you don't have to configure it or you have to go to Web.xml to configure a listener
Reference:
Log4j.rootcategory=info, stdout, R log4j.appender.stdout=org.apache.log4j.console
which the output log information belongs
%l The occurrence of the output log event where the statement that outputs the log information is in the first line of the class it is in
%m The information specified in the output code, such as a message in log (message)
%n Output a carriage return newline character, Windows platform is "RN", UNIX platform is "n"
%p output priority, or debug,info,warn,error,fatal. Debug if the debug () output is called, and so on
%r The number of mil
of the class to which the output log information belongs
%l The occurrence of the output log event where the statement that outputs the log information is in the first line of the class it is in
%m The information specified in the output code, such as a message in log (message)
%n Output a carriage return newline character, Windows platform is "RN", UNIX platform is "n"
%p output priority, or debug,info,warn,error,fatal. Debug if the debug () output is called, and so on
%r The nu
##############################
Log4j.appender.r=org.apache.log4j.jdbc.jdbcappendeLog4j.appender.r.url=jdbc:mysql://localhost/log4jdemLog4j.appender.r.user=defaulLog4j.appender.r.password=defaultLog4j.appender.r.sql=insert into jdbctest (message) VALUES ('%d-%c-%p-%m ')##################################################The first line tells Log4j,r is the type of jdbcappender. The second line declares the URL of the database that we want to log.The third
Website to publish, in order to track some logs, need to use log4j, so I studied the log4j configuration
Post a configuration source file that you used first log4j.properties
Log4j.rootlogger=debug, console, FILE
# # for CONSOLE
log4j.appender.console= Org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org
Configure interval time, print log periodicallyreceived a demand, through the log4j time print log, requirements described as follows: the need to be able to print the log regularly, the interval can be matched. When it comes to timing, first think of the Dailyrollingfileappender class, various timing, according to Datepattern, this can refer to class SimpleDateFormat class, common some of the regular settings are as follows:
'.' YYYY-MM: Month
characters to control their minimum width, maximum width, and text alignment.
Such as:
1)%20c: Specify the name of the output category, the minimum width is 20, if the category name is less than 20, the default is the right alignment.
2)%-20c: Specify the name of the output category, the minimum width is 20, if the category name is less than 20, the "-" number specifies left-aligned.
3)%.30c: Specify the name of the output category, the maximum width is 30, if the cat
log4j log File configuration
------------------------------------------------------------------------
first, the log device configuration
# root Logger (other logs are inherited from this logger)
# Default Level=debugLog4j.rootlogger=info, A1, A2 (a1,a2 for Appender)
# Level of the log
Log4j.logger.a=info,a1
Log4j.logger.a.b=debug,a1,a2
The log's inheritance rela
In a normal Web project, you can write the following XML configuration file:
Then write a servlet yourself, named Log4jinit, with the following code:
Package org.woden.controller.servlet;
Import java.io.IOException;
Import Javax.servlet.ServletConfig;Import javax.servlet.ServletException;Import Javax.servlet.http.HttpServlet;Import Javax.servlet.http.HttpServletRequest;Import Javax.servlet.http.HttpServletResponse;
Import Org.apache.log4j.xml.DOM
The log4j version I use is 1.2.16, a filter to filter the log information for an interval level when customizing Appender. However, there are still errors in the properties file configuration for a long time
Log4j:warn Failed to set the [filter] to value "Org.apache.log4j.varia.LevelRangeFilter".Log4j:error could not instantiate class [FATAL].
Then I found the answer in a foreign forum.
The propertyconfi
How do I load the log4j configuration file when the system starts?1. Customize the listener class and inherit the "Servletcontextlistener" interface: 1 PackageCn.ibeans.common;2 3 ImportJava.io.File;4 Importjava.util.List;5 6 Importjavax.servlet.ServletContextEvent;7 ImportJavax.servlet.ServletContextListener;8 9 ImportOrg.apache.log4j.Logger;Ten ImportOrg.apache.log4j.PropertyConfigurator; One ImportCn.i
During the development process, we use the log4j to output the logs, and we want to see only a subset of the log information at the time of unit testing, or to define the level of log output. This time manually specify the log4j configuration file: The following are the specific practices: The definition classes are as follows: Import java.io.FileNotFoundExcept
This method is configured in conjunction with LOG4J.
First, the libraries required to import log4j
Second, configure an initially loaded servlet in Web. Xml.
Third, the configuration log4j.properties into the project directory.
Log4j.rootlogger=error
Log4j.logger.cn.com.aliex=debug,aliex
log4j.appender.aliex= Org.apache.log4j.RollingFileAppender
log4j.app
In order for spring in a Web project to use log4j to do the following configuration:1. Add the following in Web. xml:If I have two projects here that are not configured with Web. Webapprootkey, then these two items will appear with the following exception when they are published to Tomcat:XML code
Severity: Exception sending context initialized event to listener instance of class Org.springframework.web
log4j and Web. XML Configuration Webapprootkey Issues1 in the Web. XML configurationweb.sample.rootYou can use System.getproperty ("web.sample.root") to get the property value . When you debug a Web project in Eclipse, the path to the project is a temporary path , not the real path, and you can print out the attribute values from the above statement to see where the temporary project pathsuch as: System.out
A brief introduction to the use of Org.apache.log4j.Logger in the MAVEN project.[1] First we need to find the coordinates of Org.apache.log4j.Logger and configure to Pom.xmlDependency> groupId>Log4jgroupId> Artifactid>Log4jArtifactid> version>1.2.14version> Scope>ProvidedScope>Dependency>[2] By default, you need to add a configuration file under the Src/main/java folder Log4j.properties, the specific content can be referenced below a simple example:Lo
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.