Logrotate for OpenHAB log files

Has anyone already a working log rotate configuration, that rotates the log files created by OpenHAB daily/weekly to compressed files and deletes them after e.g. 5 days?

Does anything in this answer apply (I’ve not tried it)?

Thanks for the link - it helps a bit, but still two questions left:

  • So the log rotation of OpenHAB is based on the logback mechanism and the (standard) linux logrotate is not supported?
  • It’s not getting clear for me, how (with which parameter) I can configure daily instead of weekly rotating in the logback.xml?

Correct.

I don’t know; I’ve never done it. But here is a link to what appears to be the relevant part of the logback documentation:

http://logback.qos.ch/manual/appenders.html#RollingFileAppender

The rollingPolicy/fileNamePattern determines how frequently a log is rotated. If the pattern only contains a year, it will roll once a year. If it contains year-month-day-hour, it will roll once an hour.

My openhab.log rolling policy is:

    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <file>${openhab.logdir:-logs}/openhab.log</file>
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                    <fileNamePattern>${openhab.logdir:-logs}/archive/%d{yyyy-MM,aux}/openhab-%d{yyyy-MM-dd}.log.zip</fileNamePattern>
                    <maxHistory>365</maxHistory>
            </rollingPolicy>
            <encoder>
                    <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%level] [%logger:%line] %msg%n</pattern>
            </encoder>
    </appender>

This rolls daily and keep 365 logs.

edit: it also moves the archived logs into into archive/YYYY-MM subdirectories (creating directories as necessary, and removing directories when empty)

1 Like

@justin: Many thanks for the explenation…

hey @schmidmuc - check out this message in another thread… this has come up before and is built into OpenHAB to have daily log file rotation with 30 day retention. The whole thread is in fact quite interesting should you take the time to read it.

Hi @chris , @geva

  1. What is default log rotation policy used in openhab…?
  2. In default case , after how days openhab rotates logs…?
    Currently what i know is that , zip file are getting created for 1 week.

I am just worried about maintaining my disk usage…

Thanks,
Shrikant

I’m not sure what OH1 does - it’s been a while since I used it. The settings are in the logback.xml file so I’d suggest taking a look there as you can easily adjust them in OH1 by modifying this file.

Check out the link in my post above… it lands directly on the explanation of the default configuration.

ok thanks @chris @geva

i looked into xml files , there is rotation of 30 days for zip files created.
But what are these files

  1. " openhab.log65269402444.tmp"
  2. "events.log107649675570.tmp "
  3. “2016_08_16.request.log” …?

what about openhab2?

I have set up logrotate to the following but after the rotation openhab stops writing to the logs

/var/log/openhab2/openhab.log
{
  missingok
  monthly
  rotate 1
  create 0777 openhab openhab
  compress
}

/var/log/openhab2/events.log
{
  missingok
  rotate 1
  weekly
  create 0777 openhab openhab
  compress
}

+1 on the OH2 request for log rotation.

I see appenders being defined in the org.ops4j.pax.logging.cfg file, but they seem to be using a max file size, and not any time based rotation.

If someone is interested to save some filesystem space with openHAB 2 as every log file gets rotated after a size of +10MB and it keeps 10 logs per default (=110 MB for each logfile):

I use logrotate to rotate the events.log.1 and openhab.log.1 files:

root@openhab: # cat /etc/logrotate.d/openhab2
/var/log/openhab2/openhab.log.1
/var/log/openhab2/events.log.1 {
        daily
        rotate 10
        compress
        missingok
        notifempty
        nocreate
}