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
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.lang.IllegalStateException:Web App root system property already set to different value: '
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
not be found. Because log4j is not configured, it is also configured. 5, create a new Log4j.propertier file, placed under the resource file (other tutorials can be placed directly under the SRC package, I tried not to), then run the test can be.
# # # set log Levels # # # Log4j.rootlogger = Debug, stdout, D, E # # # output to console # # # # log4j.appender.stdout = org.apache.log4j . Consoleappender Log4j.appender.stdout.Target = System.out Log4j.a
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=/
About Tomcat under multiple projects configure a log4j.properties, to output the respective log of the problem,
After the actual work of the summary and investigation, here to make a summary and memo.
To lift the log4j configuration, our common configuration method is to create a log4j.properties file for each project and write the information of its own output
file contents with the message.MAXFILESIZE=100KB: The suffix can be kb, MB, or GB. When the log file reaches that size, it scrolls automatically, moving the original content to the Mylog.log.1 file.maxbackupindex=2: Specifies the maximum number of scrolling files that can be produced.4.DailyRollingFileAppender OptionsThreshold=warn: Specifies the lowest level of output for log messages.Immediateflush=true: The default value is true, meaning that all messages will be immediately exported.File=my
Today, I saw an article about the impact of log4j on the effectiveness of the system ... Sorted as follows:
Generally, when we write log with log4j, we are used to the following records:
2005-01-11 09:57:57,816 DEBUG (bizproc.java:275) Begin to get connection ...2005-01-11 09:57:57,816 DEBUG (bizproc.java:275) Obtain connection 2345@DEFD2005-01-11 09:57:57,816 DEBUG (bizproc.java:275) Begi
;Importorg.springframework.web.bind.annotation.RequestMapping;ImportOrg.springframework.web.bind.annotation.ResponseBody;ImportOrg.springframework.web.bind.annotation.RestController;ImportCom.alibaba.fastjson.JSON;ImportYxm.zyf.love.domian.RoomDO;ImportYxm.zyf.love.mapper.RoomMapper;ImportYxm.zyf.love.utils.LoggerUtil;ImportYxm.zyf.love.utils.StringUtil;ImportYxm.zyf.love.utils.URLencord;Importyxm.zyf.love.vo.payVo; @RestController Public classHospitalpay {Private Final StaticLogger Logger = Log
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
LOG4J has a total of 5 log output levels:
FATAL (0)
Example:
Log4j.rootlogger=debug,console, FileThe above settings can crawl throw new RuntimeException ();Log4j.rootlogger=info,console, FileInfo level can not catch throw new RuntimeException ();
The reason is that this error belongs to the DEBUG level debug>info>error so INFO can't catch it.
Console output log information configuration, such as:
M
Log4j.logger.com.ibatis=debuglog4j.logger.com.ibatis.common.jdbc.simpledatasource= Debuglog4j.logger.com.ibatis.common.jdbc.scriptrunner= debuglog4j.logger.com.ibatis.sqlmap.engine.impl.sqlmapclientdelegate=debuglog4j.logger.java.sql.connection= Debuglog4j.logger.java.sql.statement=debuglog4j.logger.java.sql.preparedstatement=debugThis article is from the "bit accumulation" blog, please be sure to keep this source http://tianxingzhe.blog.51cto.com/3390077/1741292MyBatis Display SQL statement
1. Configure Log4net.config
2, the code dynamically determine which configuration to use
Log4net. Config.XmlConfigurator.Configure (New Uri (AppDomain.CurrentDomain.SetupInformation.ApplicationBase +) Log4net.config "));
public static readonly ILog Baselogger = Logmanager.getlogger ("MyLog.Base.Log");
A lot of cock Silk thinks log4j is not good to use, because it does not output to the IDE's console, haha, in fact, are configured to cause trouble, below see how I configure the console, log4j output level and output mode believe that cock silk know, here is not much to say, directly look at code comments:
# All,trace,debug,info,warn,error,fital,off
#全局项目日志配置
Log4j.rootlogger=error
#指定的包下所有的日志 (output onl
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.