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
:%d{yyyy MMM dd hh:mm:ss,sss}, output similar to: October 18, 2002 22:10:28,921#%l where the output log event occurs, including the class name, the thread that occurred, and the number of rows in the code. Example: Testlog4.main (testlog4.java:10)Examples of formatting:LOG4J.APPENDER.THISPROJECT.FILE.OUT.LAYOUT.CONVERSIONPATTERN=LOG4J--GT;%D{YYYY MMM DD HH:mm:ss,SSS}%5p{%F\:%L}-% m%nAttention:1. Small knowledge of information formattingThese parameter
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.HttpSer
The use of log4j logging is very convenient, it provides two types of log configuration, log4j.propertes and Log4j.xml, this document first posted Log4j.properties configuration method
1. Brief analysis of log4j.properties file configuration
The following gives the log4j.properties file commonly used in some informatio
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= O
Configuring log4j monitoring and file mapping and related settings in Web. xml
Web. XML code
Content configuration and parsing of log4j.properties
# Debug,info,warn,error,fatal Log level
log_level=info
log4j.rootlogger=${log_level},console,file
# LOG4J encoding format,
root directory of the project and not in the SRC directory of the project.(2) in the Javaweb project, it is placed in the SRC directory, because this time Tomcat will go to the default loading it, do not need us to manually load the log4j configuration file, only need to configure the configuration to obtain their own required logger instance can be, So we know
Search on the internet for more than n data, basic are basic configuration and detailed introduction, reproduced too much, but caused us to search the key information more trouble, after a Google and their own debugging, finally succeeded, recorded.
Suppose I need to output the log information in the Com.domain.web.monitor package to ... /logs/a.log, configure the following
#monitor是我们单独配置的com. The appendname of Domain.web.monitor
Log4j.rootlogger=e
Method One, the solution is natural to use the relative path instead of absolute path, in fact log4j Fileappender itself has such a mechanism, such as: Log4j.appender.logfile.file=${workdir}/logs/app.log
where "${workdir}/" is a variable that is replaced by the value "Workdir" in the system property. In this way, we can use System.setproperty ("Workdir", Workdir) before log4j load the
LOG4J supports two configuration file formats, one is the Java property file (the key-value) and the other is the XML format file.
Here is a description of how to configure the Java properties file.First look at the configuration file: Log4j.properties
Log4j.rootcategory=debug,stdout,r
Log4j.appender.stdout=org.apache.
operation class from beginning to end, Apache provides us with a powerful log-handling package-log4j.Log4j is an open source project for Apache, by using log4j, we can control the destination of log information delivery is console, file, GUI component, even interface server, NT Event recorder, UNIX syslog daemon, etc. We can also control the output format of each log, and by defining the level of each log information, we can control the log generatio
First, log4j sub-environment configuration:
1. Add the following configuration to the Web. XML to host spring's helper to listen for file refreshes
2. The sub-environment is also easy, as Web. XML can use system environment variables. As below, in the development machine T
Output the log configuration of java log4j to mysql, log4jmysql
Log4j supports outputting logs to files, databases, and even remote servers. This time I will share with you how to output logs to mysql.
(1)The configuration of log4j. properties is as follows:
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
When the jar package introduced in the project contains Log4j.xml or Log4j.properties, the configured log4j is overwritten, which invalidates the log4j of the configuration. To confirm whether it is overwritten, first check the path of the log4j profile read at the start of the project, you can find the service you con
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.