Enabling persistent logging
Persistent logging
Enabling persistent logging can be helpful to keep logs between reboots.
Persistent system logs
Display system logs
System logs can be displayed with this command:
journalctl --boot=-1
However, if you did not configure persistent logs you will get:
Failed to look up boot -1: Cannot assign requested address
Enable system logs
Edit config files
Note : This step might be superfluous, maybe only creating the /var/log/journal folder and refreshing systemd could work. {.is-info}
By default they are turned off in Ubuntu. We will have to enable them. The first step is to edit this file : /etc/systemd/journald.conf
nano /etc/systemd/journald.conf
Change :
[Journal]
Storage=auto
to
[Journal]
Storage=persistent
Create the log folder
When the Storage variable is set to auto as we did above, systemd will look for a folder existing at /var/log/journal, if the folder exists it will write to it.
So we need to create it:
mkdir /var/log/journal
Refresh systemd
Next tell systemd to look again for the folder
systemd-tmpfiles --create --prefix /var/log/journal
Then we can restart the logging system
systemctl restart systemd-journald
After rebooting, the journalctl command above should display the logs from the last reboot.
If you set up persistency like described above, the logs will never stop growing and could cause trouble if forgotten. You should only enable the logs persistency for some time and disable it later. {.is-warning}
Disable system logs
The logs will keep growing if not disabled. Once you have found the information you were looking for do not forget to disable them.
To do so, edit back the /etc/systemd/journald.conf to :
[Journal]
Storage=auto
Then remove the /var/log/journal folder we created above. rm -r /var/log/journal
After a reboot, you should not be able to display the log file of the last boot.
Manage logging policy through systemd
The node's logs could be managed by systemd. We could set up systemd to clean the daemon's logs after some reboots or some times.
See : systemd-tmpfiles for further documentation
Last updated