Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4j, meaning of Append = true / false

Tags:

java

log4j

log4j.appender.LOGFILE.Append = true

The doc says:

If the append parameter is true, the file will be appended to. Otherwise, the file designated by filename will be truncated before being opened.

Does it mean that if Append = true, new logs will be appended to the tail of the file? Then what does "truncated" indicate? Content will be deleted before the file being opened?

Thank you.

like image 379
Rangtian Avatar asked Feb 23 '17 08:02

Rangtian


People also ask

What is an Appender in log4j?

In the log4j2 architecture, an appender is basically responsible for sending log messages to a certain output destination. Here are some of the most useful types of appenders that the library provides: ConsoleAppender – logs messages to the System console. FileAppender – writes log messages to a file.

What is RollingFileAppender in log4j?

Log4j2 RollingFileAppender is an OutputStreamAppender that writes log messages to files, following a configured triggering policy about when a rollover (backup) should occur. It also has a configured rollover strategy about how to rollover the file.

Where do log4j logs go?

The Log4j logging settings are stored in the file app_data /conf/server/log4j. properties, where app_data is the application data folder. You can edit this file directly on the server or open it by clicking Settings > Logging.


1 Answers

Yes, "the file designated by filename will be truncated" means that any data that previously existed in the file will be gone. This is a more general concept than just logging.

Suppose you have a file initially containing the data "AB":

  • If you open it to append the value "C", the file will end up containing "ABC".

  • If you open it to truncate and then write "C", the file will end up containing "C".

  • If you open it to overwrite without truncating, the file will end up containing "CB". (This is rarely a useful option.)

like image 190
Jon Skeet Avatar answered Oct 20 '22 04:10

Jon Skeet