Log4j append = false does not work for me ... why?

I have the following configuration for log4j that outputs a csv log file. Every time my program runs, I want to run this log file, overwriting it without adding a log file. I thought I could achieve this using append=false. I know that I configured log4j correctly, as other logs output perfectly, but these are daily sliding logs that are added, which affects the desire.

Can someone tell me why append=falseit doesn't seem to work. Is there another setting that I missed?

Here is my configuration 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 indicate that my application is scheduled, and I just read that Append = false only clears the log file if the entire application is shut down and restarted. This does not help, since I need to clear this log file every time internal processes are executed.

+3
source share
2 answers

Try

log4j.appender.S.Append=false

with capital A to add

+6
source
# 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
+1
source

Source: https://habr.com/ru/post/1764762/


All Articles