How to configure per-unit log storage policy with journald?

Seems that I'm most likely out of luck with journald. Unless I'll figure out a way to spawn a independent "long-term storage" journal (like currently there are different per-user journals), but I'm not sure it's a viable and sane approach. I guess, setting up a syslogd (and logrotate) would be easier.

The feature wasn't present in late 2014, as confirmed by Lennart himself.

And it seems that it's not here yet. At least, the line "journald: allow per-priority and per-service retention times when rotating/vacuuming" is still in the TODO file (link to revision from 2016-07-11).


It is remarkably simple to generate the log file. By default all logging to journald goes to syslog as well and this default needs to be in place. The rsyslog.conf controls how the entries passed to syslog are handled. In addition the SyslogFacility defaults to daemon so the log entries for any service usually end up in the daemon.log file in /var/log.

In your service file add to the [service] section

SyslogFacility=local2

(the number can be between 0 & 7) https://www.freedesktop.org/software/systemd/man/systemd.exec.html

Modify the /etc/rsyslog.conf (find the existing lines to modify) so that local2 is logged to a specific file (first line) and ideally not logged to syslog by adding local2.none as shown (it is already in the journal).

local2.*                        /var/log/your-service-name.log
*.*;auth,authpriv.none,local2.none          -/var/log/syslog

[edit] you also need to amend the catch all

*.=info;*.=notice;*.=warn;\
        auth,authpriv.none;\
        cron,daemon.none;\
        mail,news.none,local2.none      -/var/log/messages

Of course the actual retention then needs to be done by logrotate.

HTH