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
Import the log4j jar package,Make the following configuration in Web. xmllog4j Configuration - Context-param> Param-name>WebapprootkeyParam-name> Param-value>Myapplication.rootParam-value> Context-param> Context-param> Param-name>Log4jconfiglocationParam-name> Param-value>/web-inf/log4j.propertiesParam-value> Context-param>
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
= Response.getoutputstream ();
Out.println ("
1.6 Building Two JSP pagesA successful page refreshsuccess.jsp, the code is as follows
And a failed page refreshfailed.jsp, the code is slightly
1.7 Configuring Spring's Bean file (Service)Beanreflog4j.xml
1.8 Configuring Spring's Bean file (MVC)Beanrefmvc.xml
1.9 Introduce these two Spring profiles into your existing applications, or adjust them to your project structure
1.10 Configuring Web.xml FilesAdd the
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
1. Must be to enter the corresponding LOG4J package: Log4j.x.jar Package
2. Write context in Web.xml
3. Configure the Log4j.properties property file
################ FATAL, ERROR, WARN, INFO, DEBUG
log4j.rootlogger=warn,stdout,d,e
###
stdout Log4j.appender.stdout=org.apache.log4j.consoleappender
log4j.appender.stdout.target=system.out
Log4j.appender.stdout.layout=org.apache.log4j.patternlayout
Log4j.appender.stdout.layout.ConversionPattern
The simple configuration of log4j makes it more and more applications: The log4j configuration file realizes output to console, file, rollback file, send log mail, output to database log table, custom label and so on. Choose its one or two use is enough, Log4j.rootlogger=debug,console,a1,im log4j.addivity.org.apache=tr
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
Log4j a total of 5 log output levels:
FATAL (0)
Example:
Log4j.rootlogger=debug,console, FileThe above settings can fetch the throw new RuntimeException ();Log4j.rootlogger=info,console, FileThe info level will not catch the throw new RuntimeException ();
The reason is that this error belongs to DEBUG level debug>info>error so INFO cannot be caught
Console output log information configuration, such as
the project is actually published, it cannot be done, the efficiency is not said, we can not view these logs.Side dishes of the project with the log4j, it has a configuration file, called Log4j.properties, the configuration is roughly as follows:Log4j.rootlogger = INFO, RLOG4J.APPENDER.R = Org.apache.log4j.RollingFileAppenderLog4j.appender.r.file =/home/westjava
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
The spring framework plays an increasingly important role in the development of Java EE, and learning the Spring framework configuration in the Web is the first step in the practice, and its importance is self-evident.
First download the release package to the spring official website, and the unpacked jar package is shown in the following illustration:
Then go to the Apache website download the 1.2.x version of the
First you need to configure the Web.xml inside:
Then you need to write an implementation class
Package com.free.core.util;
Import Java.io.File;
Import Javax.servlet.http.HttpServlet;
Import Org.apache.log4j.xml.DOMConfigurator;
public class Log4j extends HttpServlet {
private static final long serialversionuid = -4046002537330149394l;
public void init () {
String path = This.getservletcontext (). Getrealpath ("/");
String f
Recently used Org.slf4j.Logger, and suddenly found log also have a lot of wins to consider. This is a simple introduction to the configuration bar.
WEB Project under the words, first located in Web-app/web-inf/web.xml this everyone is very familiar with the bar ~ inside the configuration as follows
See above, must be through this loaded, first set the environment variable log4jconfiglocation=/
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.