`

log4j文件日志配置

 
阅读更多

 下面是一段最常见的日志配置模板:

#输出到控制条to console#
log4j.rootLogger = DEBUG,Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.Target=System.out
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} [%c]-[%p] %m%n

#输出到文件to file#
#error/warn/info/debug#
log4j.category.com.mylog.admin = debug,outputLog
log4j.appender.outputLog=org.apache.log4j.RollingFileAppender
log4j.appender.outputLog.Threshold=DEBUG
log4j.appender.outputLog.File=C:/logs/mylog.log
log4j.appender.outputLog.encoding=GB2312
log4j.appender.outputLog.layout=org.apache.log4j.PatternLayout
log4j.appender.outputLog.layout.title=Parser Log
#use KB\B\MB\G
log4j.appender.outputLog.MaxFileSize=20MB
log4j.appender.outputLog.Append=true
log4j.appender.outputLog.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} [%c]-[%p] %m%n

 

在控制台输出的格式如下:

2011-11-16 18:57:06,018 [com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler]-[DEBUG] Entering nullPropertyValue [target=[com.opensymphony.xwork2.DefaultTextProvider@1a8739b], property=struts]
2011-11-16 18:57:06,018 [com.opensymphony.xwork2.config.ConfigurationManager]-[DEBUG] Checking ConfigurationProviders for reload.
2011-11-16 18:57:06,018 [org.springframework.orm.hibernate3.SessionFactoryUtils]-[DEBUG] Processing deferred close of Hibernate Sessions
2011-11-16 18:57:06,018 [com.opensymphony.xwork2.config.ConfigurationManager]-[DEBUG] Checking ConfigurationProviders for reload.
2011-11-16 18:57:06,018 [org.springframework.orm.hibernate3.SessionFactoryUtils]-[DEBUG] Processing deferred close of Hibernate Sessions

 

 

生成log文件格式如下:

2011-11-16 18:56:03,554 [org.springframework.jdbc.datasource.DataSourceUtils]-[DEBUG] Returning JDBC Connection to DataSource

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics