logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "lambdadaku@gmail.com" <lambdad...@gmail.com>
Subject Rolling file appender
Date Thu, 04 Aug 2016 11:43:10 GMT
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

Mime
  • Unnamed multipart/related (inline, None, 0 bytes)
View raw message