Recently not very busy, looked at the log4j, and then see log4j inside there are appender to mail functions, the individual did a bit of understanding and experiments, wrote a simple demo did a point test.
Log4j the role of sending log messages:Project error information can be reflected in time (real-time) to project maintenance personnel and related principals.A
Webapprootkey of the two projects forXML code Application Path - Context-param> Param-name>WebapprootkeyParam-name> Param-value>Webapp.root1Param-value> Context-param> Application Path - Context-param> Param-name>WebapprootkeyParam-name> Param-value>Webapp.root2Param-value> Context-param>So there will be no conflict.After is defined, the absolute path to root is written to the system variable when the Web Container boot . then
In general, we will directly log4j.properties placed in the SRC directory, so that the system will automatically find, in fact, is placed under the Web-inf/classes file. This path is classpath, so you can find it directly. We wrote the logger as follows
public class Hellolog4j {public static Logger Logger = Logger.getlogger (Hellolog4j.class);
public static void Main (string[] args) {Logger.debug (' This is debug message. ');
Logger.info ("This is info.");
Logger.error ("
Log4j.properties file:Log4j.rootlogger=debug, Console #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]-%m%n log4j.logger.java.sql.resultset=info log4j.logger.org.apache=info Log4j.logger.java.sql.connection=debug Log4j.logger.java.sql.statement=debug Log4j.logger.java.sql.preparedstatement=debug In this way, the SQL statements and some debugg
1, the first page in the Web-inf directory under the new log4j.properties configuration file, the contents are as follows: log4j.rootcategory = Info,dailyfile log4j.appender.dailyFile =org.apache.log4j.dailyrollingfileappenderlog4j.appender.dailyfile.threshold = DEBUG log4j.appender.dailyFile.ImmediateFlush =true log4j.appender.dailyfile.append =true log4j.appender.dailyfile.file =c:/logs/ Log.loglog4j.appender.dailyFile.DatePattern =yyyy-mm-d
# ${webapp.root}: Log files are stored in the project directory ${catalina.home}: Log files are stored in the Tomcat directory
XML configuration Mode 1
The maximum number of log files configured for Maxbackupindex is 20, each log file size is 10MB. Save different levels of log information to different files: Debug.log, Info.log, Warn.log, Error.log, etc.
When the number of log files reaches 20, this configuration
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
HibernateLog4j.logger.org.hibernate.tool.hbm2ddl=debugLog4j.logger.org.hibernate.engine.transaction=debugMybatisAdd the following configuration in the MyBatis configuration1 Settings > 2 name= "Logimpl" value= "log4j"/>3 settings>Add the following configuration in spring's sqlsessionfactory configuration1 BeanID= "Sqlsessionfactory"class= "Org.mybatis.sp
The problem of setting up the Spring DM 2.0 Environment log4j problem Solving method isFirst, the introduction of SpringDM2.0 bundle, the final completion as shown:Note: To introduce Slf4j.api, slf4j.log4j, slf4j.org.apache.commons.logging and org.apache.log4j, these four are related jars of SPRINGDM log processing. However, only the introduction of these four, at this time the log system will still not start normally, the details look at the followin
This article only records the successful configuration of a tomcat and does not explain the detailed use of the log4j configuration.
This configuration generates a new log file (Debug level: Log.log) (Error level: Error.log) on a daily basis under Tomcat's Logs folder, and then modifies the name of the previous day's l
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: ' webapp.root ' = [C:\Program Files (x86) \apache SOFTW is Foundation\tomcat 6.0\webapps\d
FileName log4j.properties stored in the web-inf/classes of the project
# for Jboss:avoid to setup log4j outside $JBOSS _home/server/default/deploy/log4j.xml!
# for all other servers:comment out of the log4j listener in Web.xml to activate log4j.
#log4j. Rootlogger=info, stdout, logfile, DATABASE
Log4j.rootlogger=info,
1: Establish log4j.properties files
2: Placement Path/web-inf/classes
3: The standard contents are as follows
------------------### Direct log messages to stdout ###Log4j.appender.stdout=org.apache.log4j.consoleappenderLog4j.appender.stdout.target=system.outLog4j.appender.stdout.layout=org.apache.log4j.patternlayoutLog4j.appender.stdout.layout.conversionpattern=%d{absolute}%5p%c{1}:%l-%m%n
### Direct messages to file Hibernate.log ####log4j. Appender.
First paste on the project reference address: http://doc.okbase.net/fengshizty/archive/126397.html here to create the steps do not explain too much, just for the case to create a demo of some personal feelings to say. 1, The first use of the database is MySQL, the data table structure to look at the link, because the new table and insert the data is done in the console,So it's a lot of trouble. If you're just starting out with MySQL, choose your own workbench visualizer or use the Heidisql visua
Sometimes it is necessary to print the debug information of the third party jar when checking the problem, if all jars are printed, the log file will be very large, this time can be configured log4j to print only the specified jar debug information or package, and output to a new file.For example: I only printed here MyBatis below DataSource This package debug information to the Debug.logLog4j.logger.org.apache.ibatis.datasource.pooled=debug, test1log
When two or more projects are deployed under Tomcat, it is best to define the Webapprootkey parameters in the Web.xml file, which, if not defined, will default to "Webapp.root", as follows:
Best newspaper The parameter values for each item are different to avoid project conflicts
Serious: Exception sending context initialized event to listener instance of class Org.springframework.web.util.Log4jConfigLis TenerJava.lang.IllegalStateException:Web App root system property already set to different
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.