I know there has been a lot of discussion about logging here, so much that although I’ve done a cursory search I admit I haven’t read all the threads so apologies if what I’m posting is a duplication or is no longer relevant.
Anyway I thought I’d just post details of a simple change I made to my system to record it for myself and so that others can use it if they wish.
On my system, which is still 9.9.8 low-write, /var/log is a tmpfs so logs don’t cause excessive writes to the SD card. With the log level settings I have and the standard logrotate config I don’t have problems with the logs becoming too big that some have experienced.
So I’m happy with the system with one exception. systemd-journald also logs into this tmpfs. Now systemd will happily log into a tmpfs under /run/log/journal and is designed to log into a persistent filesystem under /var/log/journal if a permanent record is desired. I would like a persistent journal in case there are problems when booting or shutting down, or other unexpected crashes.
Since it’s not possible to reconfigure journald’s log location, we need to make that location persistent. So here’s what I did:
- Made a directory /home/pi/data/journald.logs
- Set ownership to
root:systemd-journaland modes to
- Made a directory /var/log/journal
- Added a line to /etc/fstab:
/home/pi/data/journald.logs /var/log/journal none defaults,bind 0 0
sudo mount /var/log/journal
sudo systemctl restart journald.service
I believe that in more recent systems /home/pi/data is no longer where data is stored, so it would be more appropriate to put it in /var/lib. I think there’s an error in the current setup in that there are separate directories under /var/lib for phpfina and phptimeseries. I think there should instead be a directory /var/lib/emoncms and the individual data directories and the journald logs should be placed under that. Applications keep their state information together in subdirectories.
Possibly journald logs would be better somewhere else - I’ll try to find out. Note that journald already has features to minimise writes and limit file sizes and suchlike, so there should be no worries about writing persistent logs to the SD card.