You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by "lambdadaku@gmail.com" <la...@gmail.com> on 2016/08/04 11:43:10 UTC

Rolling file appender

Hi,

I wanted to achieve daily logging with the log4j2 (v2.6.2), the default
behaviour (as it was with the log4j v1.2.x) is not expected instead a new
file is created for every log message. I have pasted below the sample code
and the properties file.

Code:

public static void main(String[] args) throws Exception {
        while (true) {
          log.info("test info");
          Thread.sleep(1000);
        }

    }

Properties Configuration:
...
appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
appender.rolling.fileName = ./${dirname}/${filename}.${fileext}
appender.rolling.filePattern =
${dirname}/${filename}-%d{MM-dd-yy-HH-mm-ss}-%i.log
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = [%-5level] %d{ISO8601} [%t] %c{1} - %msg%n
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.time.interval = 1
appender.rolling.policies.time.modulate = true
...

[image: Inline image 1]

and the file contents in each of the above mentioned file is:
[INFO ] 2016-08-04T13:30:02,454 [main] Log4jTest - test info

Do you see any issues with the property configuration?

Additionally, is it possible to create tar/zip archive of all the files
after a week or so?

Cheers,
L