Max_G
(Max G)
January 1, 2019, 12:35pm
1
How do I achieve the following in OHv2:
rotate openhab and events logs based on
daily
compress
keep 14 days
I found the log config: /var/lib/openhab2/etc/org.ops4j.pax.logging.cfg
and the relevant sections:
log4j2.appender.out.policies.size.type = SizeBasedTriggeringPolicy
log4j2.appender.out.policies.size.size = 16MB
which need changing to something like TimeBasedTriggeringPolicy?!
Where can I find the possible properties?
Or what needs to be added to achieve this?
vzorglub
(Vincent Regaud)
January 1, 2019, 8:08pm
2
Max_G
(Max G)
January 1, 2019, 9:36pm
3
Thanks… I have a crack at it…
mtrax
(Paul (mtrax))
June 15, 2019, 2:28am
4
how did you go, I would like mine rotated weekly too, should I do from log4j or using logrotate on linux?
Kimzer
(Kimzer)
March 12, 2020, 9:35am
5
Curious to how you solved this, couldnt find much up to date info on rotating them logs. Please share
Schnuecks
(Andreas Heß)
February 3, 2021, 9:35am
6
so if anyone is interested in rotation.
you have to edit userdata/etc/log4j2.xml
I have a entry for openhab.log and events.log both are daily rotated, gzip and it keeps 14 days / version of it. there is no rotation on startup because it would create an unnecessary gzip of this current day, so i leave it out. if you want it just leave the onstartuptriggerpolicy in the policies part.
for sure make a backup of this file and edit or replace the associated parts.
openhab.log
<RollingFile fileName="${sys:openhab.logdir}/openhab.log" filePattern="${sys:openhab.logdir}/openhab.%d{dd-MMM}.log.gz" name="LOGFILE">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n"/>
<Policies>
<!-- <OnStartupTriggeringPolicy/> -->
<TimeBasedTriggeringPolicy interval="1"/>
</Policies>
<DefaultRolloverStrategy>
<Delete basePath="${sys:openhab.logdir}" maxDepth="1">
<IfFileName glob="openhab.*.log.gz" />
<IfLastModified age="14d" />
</Delete>
</DefaultRolloverStrategy>
</RollingFile
events.log
<RollingRandomAccessFile fileName="${sys:openhab.logdir}/events.log" filePattern="${sys:openhab.logdir}/events.%d{dd-MMM}.log.gz" name="EVENT">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n"/>
<Policies>
<!-- <OnStartupTriggeringPolicy/> -->
<TimeBasedTriggeringPolicy interval="1"/>
</Policies>
<DefaultRolloverStrategy>
<Delete basePath="${sys:openhab.logdir}" maxDepth="1">
<IfFileName glob="events.*.log.gz" />
<IfLastModified age="14d" />
</Delete>
</DefaultRolloverStrategy>
</RollingRandomAccessFile>
2 Likes