我是log4j和记录活动的新手。
我有log4.properties文件。
**log4j.rootCategory=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n**
请建议我如何配置它以将消息记录到我的指定文件中,就像我希望它记录到某处(即c:\ abc.log);
如果您需要更多信息,请告诉我
答案 0 :(得分:1)
快速回答:
log4j.appender.FileAppender= org.apache.log4j.RollingFileAppender
log4j.appender.FileAppender.File= C:\abc.log
log4j.appender.FileAppender.MaxFileSize= 10MB
log4j.appender.FileAppender.MaxBackupIndex= 10
log4j.appender.FileAppender.layout= org.apache.log4j.PatternLayout
log4j.appender.FileAppender.layout.ConversionPattern= \#\#\#\#<%d{MMM d, yyyy h:mm:ss aa zzz}> <%p> <%c> <%X{machine}> <%X{wlsDomain}> <%t> <%X{userid}> <%X{object}> <%X{messageCode}> <%X{reqId}> <%X{reqURL}> <%m>%n
log4j.appender.FileAppender.Threshold= DEBUG
您可能还需要更新
log4j.rootCategory=DEBUG, FileAppender
或
log4j.rootCategory=DEBUG, stdout, FileAppender
答案 1 :(得分:1)
这很简单。试试这个
log4j.rootLogger=ERROR, ROOT
# Direct log messages to a log file
#log4j.appender.ROOTLOGGER=org.apache.log4j.ConsoleAppender
log4j.appender.ROOT=org.apache.log4j.RollingFileAppender
# appends the log level to file name abc.log
log4j.appender.ROOT.File=abc.log
log4j.appender.ROOT.MaxFileSize=1000KB
#Keep 5 old files around.
log4j.appender.ROOT.MaxBackupIndex=5
log4j.appender.ROOT.layout=org.apache.log4j.PatternLayout
#Format almost same as WebSphere's common log format.
# d date, t ist der Name des Threads, M ist Methodenname, C full qualified Classenname
#log4j.appender.ROOT.layout.ConversionPattern=[%d] %t %C:%l %-4p - %M%n
log4j.appender.ROOT.layout.ConversionPattern=%5p [%d] [%t] %l : %m%n
答案 2 :(得分:0)
# Root logger option
log4j.rootLogger=error, file, stdout
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=logfile.log
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
# Struts2
log4j.logger.freemarker=ERROR
log4j.logger.com.opensymphony=ERROR
log4j.logger.com.opensymphony.xwork2.ognl=ERROR
log4j.logger.org.apache.struts2=ERROR
log4j.logger.org.apache.struts2.components=ERROR
log4j.logger.org.apache.struts2.dispatcher=ERROR
log4j.logger.org.apache.struts2.convention=ERROR
# Alfresco
log4j.logger.org.alfresco=ERROR
log4j.logger.org.apache.axis=ERROR
log4j.logger.org.apache.ws=ERROR