I have simply been sticking something like this at the top of my bash scripts. This still works with systemd. (I have used it for a long time and I don't fully understand it. It just works, so I use it.)

exec 5> >(logger -t $0)
set -x

Even with systemd, the above commands give the expected output in journalctl. However, it seems that maybe I should be using something like this instead.

systemd-cat -t $0

How should I alter my current logging commands under systemd?

(I'm looking for the same kind of simple-minded solution where I can paste a few lines and get some output in the journal.)

  • 1
    Clever snippet, actually. You should dig in to understand what it's doing. – Wildcard Sep 19 '17 at 5:15
  • 2
    Thanks for that comment. You have motivated me to dig into it. :-) – MountainX Sep 19 '17 at 5:17

I would stick with logger: it works with any standards-compliant logging system, including systemd’s journal as you’ve discovered. Using systemd-cat directly would only make your scripts systemd-specific, without adding anything; in fact, modern logger is much more flexible, and provides better support for systemd-specific features than systemd-cat itself.

  • 1
    POSIX specifications for logger say that its standard input is "not used." Implementations seem to depart from that for better usability. – Wildcard Sep 19 '17 at 5:18
  • 1
    @Wildcard yes, POSIX logger is very basic, since we’re comparing with systemd here I just went with the util-linux variant. – Stephen Kitt Sep 19 '17 at 5:33
  • 1
    @Wildcard you can always use logger with xargs. – Grega Bremec Sep 19 '17 at 6:16

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.