java log4j append=false 对我不起作用......为什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3712333/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
log4j append=false does not work for me... why?
提问by Andrew Harrison
I have the below configured for log4j which outputs a csv log file. Every time my program executes I wish to start this log file a fresh by overwriting not appending to the log file. I thought I could achieve this by using the append=false
. I know that I have correctly set up log4j as other logs are outputting fine but these are daily rolling logs that are appending which is the desire affect.
我为 log4j 配置了以下输出 csv 日志文件。每次我的程序执行时,我都希望通过覆盖而不是附加到日志文件来重新启动这个日志文件。我以为我可以通过使用append=false
. 我知道我已经正确设置了 log4j,因为其他日志输出正常,但这些是附加的每日滚动日志,这是期望的影响。
Can anyone tell me why the append=false
doesn't seem to work. Is there another setting I've missed?
谁能告诉我为什么这append=false
似乎不起作用。我错过了另一个设置吗?
Here's my config code:
这是我的配置代码:
#Image output
log4j.logger.fetch.FetchDirectHolidays=debug, S
log4j.appender.S=org.apache.log4j.FileAppender
log4j.appender.S.File=xml\logs\FetchDirectHolidays.csv
log4j.appender.S.append=false
# Keep one backup file
log4j.appender.S.layout=org.apache.log4j.PatternLayout
log4j.appender.S.layout.ConversionPattern= %p , %m%n
What is wrong with my configuration?
我的配置有什么问题?
I forgot to state that my application is scheduled and I have just read that the Append=false only clears the log file if the whole application is shutdown and restarted. This does not help as I need to clear this log file each time the internal processes executes.
我忘了说明我的应用程序已安排好,我刚刚读到 Append=false 仅在整个应用程序关闭并重新启动时才清除日志文件。这无济于事,因为每次执行内部进程时我都需要清除此日志文件。
回答by crowne
Try
尝试
log4j.appender.S.Append=false
with a capital A for Append
用大写的 A 表示 Append
回答by Ibo
# Define the root logger with appender file R
log4j.rootLogger = INFO, FILE,stdout
# Define the file appender (File)
log4j.appender.FILE=org.apache.log4j.FileAppender
# Set the name of the file
log4j.appender.FILE.File=C:/user/FileName.log
# Set the immediate flush to true (default)
log4j.appender.FILE.ImmediateFlush=true
# Set the append to false, overwrite
log4j.appender.FILE.Append=false
# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=[%5p ] - %m%n
# Direct log messages to stdout (Console)
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=[%5p ] - %m%n