Change default location of logfiles (openhab.log and events.log)

Tags: #<Tag:0x00007efeb512d648> #<Tag:0x00007efeb512d580>

Hi there,

I’ve read a couple of hours on this subject but unfortunately found no working solution. I want to change the location where Openhab2 (Openhabian) writes logfiles.

Can someone push me and hopefully others in the right direction?

Thanks,
Duco

Take this as a template to edit /var/lib/openhab2/etc/org.ops4j.pax.logging.cfg to change the path where the logs are saved.

I’ll try that again. It did try to change the “log4j.appender.event.file=${openhab.logdir}/events.log” to “log4j.appender.event.file=/mnt/shares/RemoteOpenhab/events.log”, whre RemoteOpenhab is some networkshare on a nas. But nothing happend.

I now realise I didn’t set the mount to writable… Will test again.

Tested and working!

For those who want to do this:

  1. Edit /etc/fstab: add a line: (this adds the network drive on boot as a writable folder)
    //ip-of-nas/share-on-nas /mnt/shares/name-of-share cifs username=username,password=password,file_mode=0777,dir_mode=0777 0 0

  2. name-of-share can be chosen to freely

  3. edit /var/lib/openhab2/etc/org.ops4j.pax.logging.cfg: edit the line
    log4j.appender.out.file=/mnt/shares/name-of-share/openhab.log

  4. Step 3 can be repeated for every logfile you desire to write to the network drive

2 Likes

Good morning

Is anything about this changed since i was trying to edit as posted but to another local folder at first to validate function before going to nfs share. Changed booth event and out file to /media/log but what about file pattern. Could you set the variable logdir somplace else instead?

Here is an example of what I use fro zwave logging. The log file is moved to another directory and the file name pattern is changed (much better for grepping the log files, as the results will be sorted chronologically)…

log4j2.appender.ZWave.fileName = /opt/openhab2/userdata/logs/zwave/zwave.log
log4j2.appender.ZWave.filePattern = /opt/openhab2/userdata/logs/zwave/zwave.log.%d{yyyyMMddHHmmss}

Isn’t there a possibility to change the value of ${openhab.logdir} ?

I’m sure there is but I don’t know where it’s defined. Perhaps in /etc/defaults/openHAB.

You can always create a symbolic link over /car/log/openhab so it points to any location you want.

1 Like

Hi,

one way I found is to change the file /usr/lib/systemd/system/openhab2.service.

There all pathes are defined

[Service]
Environment=OPENHAB_HOME=/usr/share/openhab2
Environment=OPENHAB_CONF=/etc/openhab2
Environment=OPENHAB_RUNTIME=/usr/share/openhab2/runtime
Environment=OPENHAB_USERDATA=/var/lib/openhab2
#Environment=OPENHAB_LOGDIR=/var/log/openhab2
Environment=OPENHAB_LOGDIR=/media/usb-drive
Environment=OPENHAB_STARTMODE=daemon
EnvironmentFile=-/etc/default/openhab2

Here you can change the path to your new log directory.

3 Likes

@Schrott.Micha (or anyone)

RPi 4
Raspbian initial load, followed by Openhabian install
8G USB thumbdrive, exfat

I just tried your above recommendation, after copying my existing event and openhab logs over for appending purpose, and setting the USB thumbdrive directory permissions to rw for owner, group and others. The OPENHAB_LOGDIR now points to a directory on the thumbdrive;

logdir=/media/pi/EMTEC/openhablogs

When I check the status (systemctl status openhab2.service) I’m getting the following;

Jan 19 14:52:24 raspberrypi karaf[17392]: org.ops4j.pax.logging.pax-logging-api [log4j2] ERROR : Null object returned for RollingRandomAccessFile in Appenders. Ignored FQCN: org.apache.logging.log4j.spi.AbstractLogger
Jan 19 14:52:24 raspberrypi karaf[17392]: org.ops4j.pax.logging.pax-logging-api [log4j2] ERROR : Unable to locate appender “LOGFILE” for logger config “root” Ignored FQCN: org.apache.logging.log4j.spi.AbstractLogger
Jan 19 14:52:24 raspberrypi karaf[17392]: org.ops4j.pax.logging.pax-logging-api [log4j2] ERROR : Unable to locate appender “AUDIT” for logger config “org.apache.karaf.jaas.modules.audit” Ignored FQCN: org.apache.logging.log4j.spi.Abst
Jan 19 14:52:24 raspberrypi karaf[17392]: org.ops4j.pax.logging.pax-logging-api [log4j2] ERROR : Unable to locate appender “EVENT” for logger config “smarthome.event” Ignored FQCN: org.apache.logging.log4j.spi.AbstractLogger

Now none of the logs are being updated anywhere.

Have I missed a step somewhere?

Hello @will_stewart1a,

how are your access rights to the directory?

OH2 runs as user and group openhab. You need to give them permission to write - and of course you need to mount the drive writable.

I added these two lines to /etc/fstab

# mount USB drive
UUID=CDA2-6582        /media/usb-drive vfat   defaults,noatime,fmask=000,dmask=000  0       0

what does the command

mount | grep EMTEC

give in your case? Does it have “rw”?

And I gave everyone write access. Then it worked.

2 Likes

Hello @Schrott.Micha and thank you for your response and help.

I am proceeding to move to an SSD drive, and will employ your above advice when it arrives.

Michael,

SSD drive is installed and logging is working perfectly, thanks to your tips. I created a logfile directory with a new group that includes users pi and openhab. It’s working splendidly after multiple reboots. Much appreciated!

I also updated my frontail config file to point to the new logging directory on my SSD (for anyone following this thread, for Raspbian [and likely any Debian] it is at /etc/systemd/system/frontail.service)

Hi @will_stewart1a,

glad I could help.

It’s a nice feature of OH2 - especially for embedded systems like Raspberry - that you can set the log dir to an external SD/USB/SSD/… It keps your SD-card clean and working.

I just found out that there is even a better way to change the path.

After updating to the new version of OH (2.5.4-1) I had to redo the changes. The currently used version of systemd allows an easy overriding of configs without having to change the original file.

sudo systemctl edit openhab2.service

with this content

[Service]
Environment=OPENHAB_LOGDIR=/media/usb-drive/

also makes the change - but future upgrades will not affect that patch anymore.

1 Like