Matt
Matt

Reputation: 1244

Does Logback RollingFileAppender rename or truncate existing file

Does logback rename existing log files with a numerical suffix, then re-create the original empty log file or truncate the original log file in place after creating a copy?

I am trying to use AWS Cloudwatch Agent with a Java application that uses logback. We currently using the RollingFileAppender with FixedWindowRollingPolicy and SizedBasedTriggeringPolicy.

Upvotes: 3

Views: 1194

Answers (1)

glytching
glytching

Reputation: 47865

A RollingFileAppender is a FileAppender which can rollover log files; this appender can log to a file named myLog.log and when a given condition is met change its target to another file. It has two required sub components:

  • A RollingPolicy which performs the rollover
  • A TriggeringPolicy which determines if and when a rollover occurs

That's the background, now, onto your question ... you wrote that you are using a FixedWindowRollingPolicy so when rollover occurs Logback will rename the currentLogFle as currentLogFle1 and then create a new currentLogFle and this then becomes the active output target. So the answer to this question ...

Does logback rename existing log files with a numerical suffix, then re-create the original empty log file or truncate the original log file in place after creating a copy?

... is:

Logback will rename existing log files with a numerical suffix, then re-create the original empty log file.

There's a useful table in the docs describing this behaviour.

Upvotes: 4

Related Questions