[SOLVED] OHv2: logfile rotation daily, compression, keep 14 days

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?

https://logging.apache.org/log4j/2.x/

Thanks… I have a crack at it… :slight_smile:

how did you go, I would like mine rotated weekly too, should I do from log4j or using logrotate on linux?

Curious to how you solved this, couldnt find much up to date info on rotating them logs. Please share :slight_smile:

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