[logback-user] Rolling with compression with changing logfile name

Jonas Gröger jonas at huntun.de
Sat Apr 14 22:59:54 CEST 2018


Hello!

So we have a use case where

+ Applications get redeployed frequently (10 per day)
+ The applications run in containers (Openshift)
+ The container hostname is always different on redeploy (new container)
+ The logfile is named after the container hostname (i.e. svc-2-asdf)

Using the RollingFileAppender with a

    <file>${HOSTNAME}.log</file>

and a TimeBasedRollingPolicy with a

    <fileNamePattern>${HOSTNAME}.%d{yyyy-MM-dd_HH-mm}.log.gz</fileNamePattern>

this works fine when we do not redeploy. On redeploy however the ${HOSTNAME} changes and logs are not compressed because the RollingFileAppender only compresses on roll which is every period (here: minute) if the filename is still in the same pattern, which its not here.

Similarly the <maxHistory> and the <cleanHistoryOnStart> do not work here. For this I have created a RollingFileAppender that compresses on shutdown. You can find it here:

https://gist.github.com/JonasGroeger/34bb004b30d18d8bc12642ba03141ac6

Is there another way without this custom Appender?

-- Jonas


More information about the logback-user mailing list