Per Journald man page. This command can capture stdout/stderr, only, for running services. However, sometimes we would like to capture text logs into journald, For example, nginx access.log.

Is it possible to capture any text file using command such as tail -f into journald with systemd tools?

  • 2
    sure - you could write a service that did log-rotation and cat'd the files to the system log. No one (realistically) does this since it's a lot of unnecessary clutter. – Thomas Dickey Sep 5 '18 at 23:00
  • 2
    similar answer, but I agree with @ThomasDickey. no-one does this. – danblack Sep 5 '18 at 23:14
  • 1
    You should be writing/using systemd unit files that capture these logs to journald if that's what you're trying to accomplish. – slm Sep 5 '18 at 23:53
  • 1
    The other way of phrasing the question, oft asked in the daemontools world over the past couple of decades, is How do I persuade this program to just write its log to standard error instead of privately maintaining its own log file? – JdeBP Sep 6 '18 at 1:09

You can accomplish this using the method discussed in this SF Q&A titled: How can I send a message to the systemd journal from the command line?. This method uses the tool systemd-cat which is similar in functionality to logger.

$ echo 'hello' | systemd-cat -p info
$ echo 'hello' | systemd-cat -p warning
$ echo 'hello' | systemd-cat -p emerg

Messages would show up like this in journald:

Feb 07 13:38:33 localhost.localdomain cat[15162]: hello

You can control the identifier details that show up in the logs like this:

$ echo 'hello' | systemd-cat -t someapp -p emerg

Resulting in this type of logging:

Feb 07 13:48:56 localhost.localdomain someapp[15278]: hello

NOTE: I'd still probably implement this using an actual systemd unit file designed to capture the logs of Nginx.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.