Log4j, meaning of Append = true / false

11,302

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.)

Share:
11,302

Related videos on Youtube

Rangtian
Author by

Rangtian

Updated on September 16, 2022

Comments

  • Rangtian
    Rangtian over 1 year

    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.

    • Jon Skeet
      Jon Skeet about 7 years
      Yes, "truncated" means "shortened" - in this case, it's basically that the file will be overwritten as if it never existed before.