Skip to content

Configuring append mode log files via Syslog NG

Saverio Miroddi edited this page Aug 16, 2021 · 1 revision

On systems where Systemd is not recent enough (earlier than v240, e.g. on Ubuntu 18.04), it's not possible to configure the unit to write to the logs in append mode.

In such cases, one can send the log messages to the syslog, and send them to a separate file.

Preliminary step

As a preliminary step, after installing the unit, edit it:

systemctl edit --user --full sidekiq

and replace StandardOutput and StandardError with the following entries:

StandardOutput=syslog
StandardError=syslog

then reload the unit(s):

systemctl daemon-reload

Sidekiq's log messages will now be sent to the syslog.

Syslog-NG

Add the following entries to /etc/syslog_ng/syslog-ng.conf:

filter f_sidekiq {
  program("sidekiq");
};

log {
  source(s_src);
  filter(f_sidekiq);
  destination(d_sidekiq);
};

destination d_sidekiq {
  file("/path/to/sidekiq.log", owner("the-sidekiq-user"), group("the-sidekiq-user"));
};

and restart Syslog-NG: systemctl restart syslog-ng. The sidekiq messages will now be stored both in the file specified above, and the syslog file.

If one doesn't want the messages to be stored in the syslog file anymore, append the condition and not filter(f_sidekiq) to f_error and f_messages (again, in /etc/syslog_ng/syslog-ng.conf), for example:

filter f_error {
  level(err .. emerg)
  and not filter(f_sidekiq) # added
;};

filter f_messages {
  level(info,notice,warn)
  and not facility(auth,authpriv,cron,daemon,mail,news)
  and not filter(f_sidekiq) # added
;};

and restart Syslog-NG again.

Clone this wiki locally