category. The minimum width is 20. If the category name is smaller than 20, the "-" sign specifies the left alignment. 3) %. 30C: specify the name of the output category. The maximum width is 30. If the category name is greater than 30, the extra characters on the left will be truncated, but there will be no spaces if the value is less than 30. 4) % Category 30C: If the category name is less than 20, fill in spaces and align right. If the category name is longer than 30 characters, it will be t
Log4j is an open source project for Apache, by using log4j, we can control the destination (console, file, GUI component, even interface server) of the log information, we can control the output format of each log, by defining the level of each log information, We are able to control the log generation process in more detail. Most interesting of all, these can be configured flexibly with a single
In our project, there are some important logs to separate output to the specified file, rather than the total output to the system log file, then we log4j for us to provide such a function, below we have to step by step to see how to do. This is written in the configuration of the property, XML is similar, you want to know, you can see the official document.
The
Configuration of Java log4jLog4j has a lot of advantages, it is very convenient to use, is the configuration of some trouble, the following I introduce LOG4J configuration method.Log4j is used to record logs.The operation of the software can not be separated from the log. Logs are mainly used to record some important o
}-%p ][%f:%l][%t]--%m%n# Log output path and log file name log4j.appender.r.file=${log_home}/wenniuwuren-system.log# Single log file maximum capacity log4j.appender.r.maxfilesize=1024kb# maximum number of backup files log4j.appender.r.maxbackupindex=10# R-------------------- -----------------------------------------------------------log4j.appender.stdout= org.apache.log4j.consoleappenderlog4j.appender.stdout.layout= org.apache.log4j.patternlayoutlog4j.appender.stdout.layout.conversionpattern=%d%
Logmanager during initialization, reads the value of the log4j.configuration system variable, generates the URL of the configuration file, The default is Log4j.properties or Log4j.xml. Then use the Propertyconfigurator class to parse the Log4j.properties file.
Read the source to understand that the Propertyconfigurator class implemented the Configurator interface, overloaded the Configure method to read the properties file, and then through the overl
The performance of log4j is much better than that of system.out.println, especially when a large number of output statements are observed.
--------------------------------------------------------------------------------------------------
Download Address:
Current version, 2.0 beta3
Jar:http://www.apache.org/dyn/closer.cgi/logging/log4j/2.0-beta3/apache-log4j-2.0-
project Lib libraryMy project is the project of idea, so Lib is in the directory, but the normal JAVV Web application lib is the web directory2. After placing the jar package, we add a configuration file using log4jPut the configuration file in the Classpath directory, generally our normal situation is placed in the SRC root directory can be?
123456789101112131415161718192021222324252627282930
first, a simple introduction to the use of log4j steps
The whole is divided into the following steps: 1, the introduction of Log4j-*.*jar, the JAR package 2, add a configuration file (Log4j.xml or Log4j.properties), 3, the Packaging Log tool class in the business use. This is the traditional use of the steps, but we can directly with the Lombok wrapped Log too
, Log4j.appender.r.layout.conversionpattern=%d-[ts]%p%t%c-%m%n
9, Log4j.logger.com.johnny=debug
Customize the log level in each package, specifying that all classes under the Com.johnny package have a level of debug.
Second, loading their own configuration fileslog4j the Log4j.properties file under the default load Classpath, you need to use Domconfigurator.configure when customizing the properties file for other names ("e:/study/
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 pla
known at present.The difference between the two methods:Logfactory from common-logging bag. If using Logfactory.getlog:Pros: You can replace log4j with any logger that implements the universal log interface, and the program is unaffected.Disadvantage: Need one more common-logging package, this is barely a disadvantage.Logger from Log4j's own bag. If using Logger.getlogger:Pros: You only need a log4j jar pa
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
Use log4j without configuration files
Log4j is an open-source Java program of Apache. It has powerful functions and can be applied to different fields. It supports various types of logs, such as console, file, email, and DB. However, the configuration of log4j must also be
Booting up on your own computer is normal, booting on someone else's computer has been stuck here. Log4j:warn No Appenders could is found for logger (org.springframework.web.context.ContextLoader). Log4j:warn Initialize the log4j system Properly.log4j:WARN see http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info . Configuration files that need to b
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
For Java Framework class projects such as SSI and SSH1. Copy the Log4j.jar to the Web-inf/lib directory2. Create a log4j.properties configuration file under the source folder in the project to configure the log information3. The detailed settings in Web. Xml are as follows: The container scans the log4j configuration
Many diaosi think that log4j is not easy to use because it is not output to the IDE console. Haha, it is actually a disaster caused by configuration. The following describes how to configure log4j to the console step by step,
I believe that log4j's output level and output mode are all known. I will not talk about it here. Let's just look at the code comment:
# Al
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.