log4j output multiple custom log filesIf you need to output a separate log file in the actual application, how can you separate the required content from the original log and form a separate log file?
First look at a common log4j.properties file, which logs log in console and Test.log files:
Copy Code code as
has been successfully installed.
Mylog4j. Properties
### direct log messages to stdout ###log4j.appender.consoleout=org.apache.log4j.ConsoleAppenderlog4j.appender.consoleout.layout=org.apache.log4j.PatternLayoutlog4j.appender.consoleout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c:%L - %m%n### direct messages to file myfile.log ###log4j.appender.myfile=org.apache.log4j.DailyRollingFileAppenderlog4j.appender.myfile.File=logs/m
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
explanation of the statements in the Log4j.properties file1 This sentence is the output of the log information of level info to stdout and R, the definition of stdout and r in the following code, can be arbitrarily named. Level can be divided into off, FATAL, error, WARN, INFO, DEBUG, all, if the configuration off does not play any information, if configured as info so only display info, WARN, error log information, and DEBUG information will not be displayed, Refer to the third section to defin
The three main components of the log4j configuration file are:Logger,appender and layout, respectively, log type, log output destination, log output format.Log4j.rootlogger = [Level],appendername, Appendername, ...(Level is the error, Appendername is the output destination, this example is set to MyLog, you can define more than one) level priority is fatal, ERROR, WARN, INFO, DEBUG 5 levels. By defining the
Source: http://www.coderli.com/log4j-console-file-garbled A small problem, but it makes me feel that there are few people who really move their brains. Let me talk about it. Today encountered a small problem, log4j output to file garbled, the console is normal. Obviously the coding problem leads to. Google a search, al
log4j.properties.
So the error log is saved in the LogRecorderror.log file,
But because: DEBUG
Log4j.appender.d.threshold = Info This sentenceThe function is to output content above the info level to LogRecord.log, so the LogRecord.log file contains the error level file.
If there is any mistake, please point out, thank you.
Monday came back to find the above
Original address: http://huanyue.iteye.com/blog/574598
log4j when you specify the location of the log file is to use absolute path, so when the deployment environment is very cumbersome to change, find a number of methods on the Internet, personal feeling the following methods are more applicable:
Because spring also loads log4j.properties, log information is se
'. ' Yyyy-mm-dd
This is the default value, which scrolls every day at midnight
'. ' Yyyy-mm-dd-a
Scroll every day at midnight and noon
'. ' Yyyy-mm-dd-hh
Scroll in every one hours
'. ' Yyyy-mm-dd-hh-mm
Rolling in every Minute
'. ' Yyyy-ww
The first day of the week depending on the regional setting is scrolled
The following is a sample configuration
The log4j configuration file (Configuration file) is used to set the level, the repository, and the layout of the logger, and it can be set in key=value format or in XML format information. By configuring, you can create a log4j running environment. The
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
...Log4j.appender.appenderName.option = ValuenAmong them, LOG4J provides the following types of Appender:Org.apache.log4j.ConsoleAppender (console),Org.apache.log4j.FileAppender (file),Org.apache.log4j.DailyRollingFileAppender (generates a log file every day),Org.apache.log4j.RollingFileAppender (creates a new file whe
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
. XML in a directory similar to the followingFind out if the following statement is available org.springframework.web.util.log4jconfiglistener NBSP; org.springframework.web.context.contextloaderlistener If there is, first check whether the statement is complete, the monitoring and declaration order can not be reversed, otherwise it will error; second, look at the code where the address is not wrong, the addr
third step: the corresponding modification of the attributes, before the change must know what these are doing, in the second part of the explanation.
Step Fourth: Add the relevant statement to the class where you want to output the log:
Define attributes: Protected final log = Logfactory.getlog (GetClass ());
In the appropriate method:
if (log.isdebugenabled ()) {
Log.debug ("System ...");
}
Ii. Description of Log4j
1 Og4j.rootcategory=info, stdout
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
%p: Output log information priority, i.e. Debug,info,warn,error,fatal,%d: the date or time of the output log point-in-time, the default format is ISO8601, or the format can be specified thereafter, for example:%d{yyy MMM dd hh:mm:ss,sss}, Output is similar: October 18, 2002 22:10:28,921%r: The number of milliseconds to output from the application boot to the output of this log information%c: The class that the output log information belongs to, usually the full name of the class in which it is l
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.