In older Linux systems, the logger command can be used to send a log message to syslog.

Reading where does logger log its messages to in Arch Linux?, it seems that syslog messages and the logger command line app only talk to the systemd journal if a socket for message forwarding is set up.

So what's the modern equivalent of the logger command? How can I send a message directly to the systemd journal from the command line?

  • we can also configure rsyslog to take journalctl logs as input and then output them as files also via rsyslog. – Luv33preet Jun 8 '17 at 7:15
  • logger logs to the journal. – Cliff May 8 at 3:31
  • @Cliff logger is part of syslog, uses syslog facilities and priorities, etc. – mikemaccana May 8 at 13:31
  • @mikemaccana I know, but there is no command-line way I can find to fully interface with journald. And sure, logger can use syslog facilities and priorities, but it doesn't have to. But the logger manpage's "See Also" section mentions systemd more than syslog. man7.org/linux/man-pages/man1/logger.1.html Plus, systemd-cat does not allow me to set custom fields, so what is the point of using it instead of logger? – Cliff May 9 at 17:00

systemd-cat is the equivalent to logger:

echo 'hello' | systemd-cat

In another terminal, running journalctl -f:

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

Priorities are specified just by part of the string:

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

Warnings are bold, emergencies are bold and red. Scary stuff.

You can also use an 'identifier' which is arbitrary, to specify the app name. These are like syslog's old facilities, but you're not stuck with ancient things like lpr uucp nntp or the ever-descriptive local0 through local7.

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

Is logged as:

Feb 07 13:48:56 localhost.localdomain someapp[15278]: hello
| improve this answer | |
  • 10
    Very useful. You can filter to the log messages created with -t using the following command: journalctl -t someapp – Att Righ Oct 1 '17 at 13:05

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.