Log4j configuration commonly used in general can be used in two ways,. Properties and. Xml, give two simple examples below:
A, log4j.properties
# # # Set the domain corresponding to the level org.zblog INFO, DEBUG, WARN, ERROR and output to A1, A2 # #
log4j.category.org.zblog = ERROR, A1
log4j.category.org.zblog = INFO, A2
log4j.appender.A1 = org.apache.log4j.ConsoleAppender
# # # Set the output to A1, as ConsoleAppender (console) # #
log4j.appender.A1.layout = org.apache.log4j.PatternLayout
# # # Set the layout format of the output of A1 PatterLayout, (the flexibility to specify the layout mode) # #
log4j.appender.A1.layout.ConversionPattern =% d {yyyy-MM-dd HH: mm: ss, SSS} [% c] - [% p]% m% n
# # # Configure the log output format # #
log4j.appender.A2 = org.apache.log4j.RollingFileAppender
# # # Set the output to A2 to a file (the file size reaches the specified size when generating a new file) # #
log4j.appender.A2.File = E: / study/log4j/zhuwei.html
File location # # # # #
log4j.appender.A2.MaxFileSize = 500KB
# # # # # File size
log4j.appender.A2.MaxBackupIndex = 1
log4j.appender.A2.layout = org.apache.log4j.HTMLLayout
# # Specify the output methods using html
Second, log4j.xml
<? Xml version = "1.0" encoding = "GB2312"?>
<! DOCTYPE log4j: configuration SYSTEM "log4j.dtd">
<Log4j: Configuration xmlns: log4j = " http://jakarta.apache.org/log4j/ ">
<appender name="org.zblog.all">
<! - Set Channel ID: org.zblog.all and output mode: org.apache.log4j.RollingFileAppender ->
<param name="File" value="E:/study/log4j/all.output.log" /> <! - Set File parameters: the log output file name ->
<param name="Append" value="false" /> <! - Set whether to restart the service, the basis of the original log to add a new log ->
<param name="MaxBackupIndex" value="10" />
<layout>
<param name="ConversionPattern" value="%p (%c:%L)- %m%n" /> <! - project and set the output file format ->
</ Layout>
</ Appender>
<appender name="org.zblog.zcw">
<param name="File" value="E:/study/log4j/zhuwei.output.log" />
<param name="Append" value="true" />
<param name="MaxFileSize" value="10240" /> <! - set the file size ->
<param name="MaxBackupIndex" value="10" />
<layout>
<param name="ConversionPattern" value="%p (%c:%L)- %m%n" />
</ Layout>
</ Appender>
<logger name="zcw.log"> <! - set domain limitation that zcw.log log domain and the following are the corresponding output channel to the following ->
<level value="debug" /> <! - set the level ->
<appender-ref ref="org.zblog.zcw" /> <! - with the previous corresponding to the channel id ->
</ Logger>
<root> <! - set up to receive all output channels ->
<appender-ref ref="org.zblog.all" /> <! - with the previous corresponding to the channel id ->
</ Root>
</ Log4j: configuration>
Third, the configuration file loading method:
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.xml.DOMConfigurator;
public class Log4jApp {
public static void main (String [] args) {
DOMConfigurator.configure ("E: / study/log4j/log4j.xml ");// load. Xml file
/ / PropertyConfigurator.configure ("E: / study/log4j/log4j.properties ");// load. Properties files
Logger log = Logger.getLogger ("org.zblog.test");
log.info ("test");
}
}
Fourth, the project uses log4j
In web applications, configuration files can be loaded in a separate servlet, and configure the servlet in the web.xml in the application startup time to load. For many projects, you can set one output to each individual channel, so that everyone in the building in the Logger, use your own domain name, so that debugging information output to your log file.
Fifth, common output format
#-X Number: X information output left-justified;
#% P: log information level
#% D {}: log message generation time
#% C: location of log information (class name)
#% M: the log specific information
#% N: newline output log information
Log4j configuration used
2010-12-15 来源:本站原创 人气:103
-
Log4j configuration file example _jackey
2010-03-29
Introduction: Recent always use log4j stuff, I think this a good tool for you than I am familiar with logs, presumably have a taste of its rich and powerful. We all know that both log4j and common-logging with the use of. Today, I own the log4j stuff
-
log4j configuration instructions (found a relatively long)
2008-07-21
Log4j is an open-source Apache project, through the use of Log4j, we can control the destination of the log information transmission is the console, file, GUI components, and even socket servers, NT event logger, UNIX Syslog daemon, etc. ; we can als
-
log4j configuration file Xiangjie
2009-03-18
log4j configuration Xiangjie The first step: Add log4j-1.2.8.jar to the lib. Step Two: In the CLASSPATH established under the log4j.properties. Reads as follows: 1 log4j.rootCategory = INFO, stdout, R 2 3 log4j.appender.stdout = org.apache.log4j.Cons
-
Log4j configuration file!
2009-07-26
Log4J configuration file (Configuration File) is used to set the logger level, storage devices and layout, which can be accessed by key = value format, settings or xml format settings. Through the configuration, you can create a Log4J runtime environ
-
main method reads the Log4j configuration
2008-11-16
log4j conf: log4j.rootLogger = INFO, HGJ log4j.appender.HGJ = org.apache.log4j.DailyRollingFileAppender log4j.appender.HGJ.layout = org.apache.log4j.PatternLayout log4j.appender.HGJ.layout.ConversionPattern =%-5p:% d -% m% n log4j.appender.HGJ.File =
-
log4j configuration Xiangjie
2008-11-09
log4j configuration Xiangjie the first step: Add log4j-1.2.8.jar to the lib. Step Two: In the CLASSPATH established under the log4j.properties. Reads as follows: 1 log4j.rootCategory = INFO, stdout, R 2 3 log4j.appender.stdout = org.apache.log4j.Cons
-
[Change] Log4j configuration of more comprehensive
2010-03-24
[Change] Log4j configuration of more comprehensive log4j.rootLogger = DEBUG, CONSOLE, A1, im log4j.addivity.org.apache = true # Used in the console log4j.appender.CONSOLE = org.apache.log4j.ConsoleAppender log4j.appender.Threshold = DEBUG log4j.appen
-
log4j configuration instructions
2010-05-07
Java programming using specific Log4j can refer to the following example: 1, the establishment of Logger instance: Syntax said: public static Logger getLogger (String name) Actual use: static Logger logger = Logger.getLogger (ServerWithLog4j.class.ge
-
[Change] log4j configuration Xiangjie
2010-06-08
>>>> 1. Overview Introduction Log4j development of reusable components in the stress of today, in addition to its own from start to finish development of a reusable logging operations outside class, Apache provides us with a powerful logging o
-
Log4J configuration file with auto-archive
2010-06-18
############################################# # # Log4J configuration file with auto-archive # ############################################# # Define the default log level and output object log4j.rootLogger = debug, file, console # Set the console ou
-
Log4j configuration steps are detailed
2010-06-29
Log4J configuration file (Configuration File) is used to set the level of the recorder, storage devices and layout, it can then set the key = value format or xml format settings. Through configuration, you can create a Log4J runtime environment. 1. C
-
[Reprinted] log4j configuration file Xiangjie
2010-08-06
1, log4j configuration file shows the basic meaning of Second, Log4j log management system is simple to use instructions Third, configure Log4j log4j configuration file Xiangjie 1: log4j configuration file shows the basic meaning of log4j.properties
-
log4j supporting code to support combine multiple log4j configuration file.
2010-08-06
1. When people develop a program, use the log4j, and each write their own log4j, properties configuration file, In the process, when combined, if you want to merge configuration files, then at a later development and maintenance will create some inco
-
[Change] log4j configuration Explained
2010-08-13
Original Address: http://blog.csdn.net/djhyoo/archive/2007/06/09/1645525.aspx log4j configuration Explained the first step: Add log4j-1.2.8.jar to the lib next. Step Two: In the CLASSPATH established under log4j.properties. As follows: 1 log4j.rootCa
-
Spring Log4j Configuration Guide
2010-08-29
In our daily development, logging is very important. We can test to detect changes in the code variable, tracking code to run track. Also can create some basic application-level logging. Apache Log4j is an open source project, it provides a fine log
-
Log4j configuration of more comprehensive
2010-08-29
Log4j configuration of more comprehensive log4j.rootLogger = DEBUG, CONSOLE, A1, im log4j.addivity.org.apache = true # Used in the console log4j.appender.CONSOLE = org.apache.log4j.ConsoleAppender log4j.appender.Threshold = DEBUG log4j.appender.CONSO
-
SSH Log4j configuration information
2010-09-02
web.xml configuration information <! - Log4j configuration information -> <context-param> <param-name> log4jConfigLocation </ param-name> <param-value> / WEB-INF/log4j.properties </ param-value> </ Context-param>
-
By date. Time or size of the generated log file log4j configuration
2010-09-27
By date, time, or size of the generated log file log4j configuration http://dev.csdn.net/article/31827.shtm We developed the B / S structure, system, server run normally have daily log. Save the form into a log file, when we often encounter a problem
-
Detailed Log4j configuration, it is really detailed look at the backup
2010-10-09
http://quanweilu.blog.sohu.com/143065381.html http://quanweilu.blog.sohu.com/143065571.html http://quanweilu.blog.sohu.com/143065702.html http://quanweilu.blog.sohu.com/143065789.html log4j configuration file has three main components: Logger, Append
-
Log4j configuration problem webAppRootKey parameters d (rpm)
2010-10-10
Web project to make use of Log4j to do the following Spring configuration: 1, in the web.xml, add the following: <! - If not defined webAppRootKey parameters, then webAppRootKey is the default "webapp.root". But the best settings, to avoid na
热门文章
-
Mysql Can't find file: '. / Mysql / host.frm' (errno: 13) solution
1 -
Learning to use regular expressions
2 -
J2EE Clustering Article Notes
3 -
Links an internal post - Calculation of mass storage
4 -
System.getProperty () parameter Guinness, keep for future use
5 -
Batch delete files ClearCase
6 -
On database design experience (1,2)
7 -
Ajax 学习资源 中外都有
8 -
Dropbox:一个不错的文件存储和共享服务
9 -
div+css+js模拟tab切换效果 事件绑定 IE,firefox兼容
10
小编推荐
- The use of chitosan antibacterial finishing of textile care
- Hibernate3 applications in the treatment of batch updates and bulk delete (Revised Edition)
- How to delete all the sub-div
- GridView 72-like stunt
- Tomcat's server.xml on the number of instructions in the host node
- ExtJS build an application using (d)
- [Ruby novice teaching] windows development environment on the description of jruby
- Create a crontab example
最新更新
- JavaScript using the timer incoming "2010-10-15" within the parameters were eval
- php Study Notes (php.inc configuration explain)
- Server Section = ResponseStatusLine commit protocol conflict solution
- Chinese language pack addresses Eclipse
- Write a simple Java program file directory monitor
- 5 the word back East to download the new (strong word memory software)
- Answer: SQL interview questions: get the highest score of each type, the highest number of units of a certain type, a second type of unit!
- 拼音输入法引擎 pye1
- 医药电商B2C遇增量不增利难题:爆发最快得3年
- JS面向对象编程浅析
service integration bus websphere jndi tomcatPowered by JForum fitness forumsweblogic proxy command connect http 1.1managediframe extjs 3.4 examplehttp: www.3177.comhttp: erp.nfgroup.com.cn:8000hibernate:ERROR: No database selectedhttp: http 10.5.65.239:90802.http: t.cn RVpx2wI