struts日志配置
一般使用log4j:
首先,需要将log4j-1.2.12.jar拷贝到\WEB-INF\lib中,然后配置属性文件。
属性文件存放在:WEB-INF下,如下:
commons-logging.properties配置总日志
simplelog.properties配置SimpleLog日志
log4j.properties配置Log4j日志
默认情况下,commons-logging日志选择使用SimpleLog,可以注释掉原来的配置代码,而采用更流行的Log4j。
commons-logging.properties:
Xml代码
##setLogasLog4J
orgorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
##setLogasSimpleLog
#orgorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
simplelog.properties:
Java代码
org.apache.commons.logging.simplelog.defaultlog=info
log4j.properties:
Java代码
##LOGGERS##
#definealogger
#log4j.rootLogger=DEBUG,console,file
log4j.rootLogger=INFO,console,file
##APPENDERS##
#defineanappendernamedconsole,whichissettobeaConsoleAppender
log4j.appender.console=org.apache.log4j.ConsoleAppender
#defineanappendernamedfile,whichissettobeaRollingFileAppender
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=e:/MyTrain/Java_Web_Frame/JavaLog/helloapp_log.txt
#setthelog'ssize
log4j.appender.file.MaxFileSize=1000KB
log4j.appender.file.MaxBackupIndex=20
##LAYOUTS##
#assignaSimpleLayouttoconsoleappender
log4j.appender.console.layout=org.apache.log4j.SimpleLayout
#assignaPatternLayouttofileappender
log4j.appender.file.layout=org.apache.log4j.PatternLayout
#Fordebug
#log4j.appender.file.layout.ConversionPattern=[%-5p][%t][%C][%d{yyyy-MM-ddHH:mm:ss}]%m%n
#Fordeployment
log4j.appender.file.layout.ConversionPattern=[%-5p][%d{yyyy-MM-ddHH:mm:ss}]%m%n