一個不錯的log4j.properties例子

# Set root logger level to WARN and append to stdout
log4j.rootLogger=WARN, stdout, error
#WARN爲log輸出級別,stdout,error爲該log的別名,下面將用到
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout web

# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%d %5p (%c:%L) - %m%n spring

# Print only messages of level ERROR or above in the package noModule.
log4j.logger.noModule=FATAL apache

# OpenSymphony Stuff
log4j.logger.com.opensymphony=INFO
log4j.logger.com.opensymphony.webwork=DEBUG app

# Spring Stuff
log4j.logger.org.springframework=INFO spa

#################################
#                       錯誤信息 #
#################################
log4j.appender.error=org.apache.log4j.DailyRollingFileAppender
log4j.appender.error.File=E:/MyDoc/WorkSpace/webworkroot/logs/errors.log
log4j.appender.error.layout=org.apache.log4j.PatternLayout
log4j.appender.error.layout.ConversionPattern=[%d]-%-5p (%F:%L)|%m%n
log4j.appender.error.DatePattern='.'yyyy-MM-dd
log4j.appender.error.Threshold=ERROR 開發

###################################
#                       CONSOLE #
################################# io

log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=(%F:%L)|%m%n console

log4j.appender.errorcsle=org.apache.log4j.ConsoleAppender
log4j.appender.errorcsle.layout=org.apache.log4j.PatternLayout
log4j.appender.errorcsle.layout.ConversionPattern=%-5p (%F:%L)|%m%n
log4j.appender.errorcsle.Threshold=ERROR file

##################################
#                       業務系統 #
#################################
log4j.logger.cn.vesung=DEBUG, logic call

log4j.appender.logic=org.apache.log4j.DailyRollingFileAppender
log4j.appender.logic.File=E:/MyDoc/WorkSpace/webworkroot/logs/logic.log
log4j.appender.logic.layout=org.apache.log4j.PatternLayout
log4j.appender.logic.layout.ConversionPattern=[%d]-%-5p (%F:%L)|%m%n
log4j.appender.logic.DatePattern='.'yyyy-MM-dd

其實業務系統和錯誤信息的輸出定義對開發人員來講是最重要的。

相關文章
相關標籤/搜索