Hacker News new | ask | show | jobs
by z3t4 3446 days ago
My main complain about systemd is that it does not log the stderr stream !!
1 comments

It does log the standard error stream. The default value of StandardError= is inherit, which will cause stderr to go to the same place that stdout goes, which by defaults to journal. This is documented in systemd.exec(5).

If not overriden in an individual service's unit file, perhaps you have set DefaultStandardError= in /etc/systemd/system.conf?

The problem is that it doesn't store "unit" meta-data for stderr, so you can not see stderr logs with journalctl -u nameOfUnit or systemctl status nameOfUnit
I do not find this to be the case. Right now I'm looking at the journal and observing the existence of _SYSTEMD_UNIT fields for messages that have been written to a process's standard error stream.
Can you see them when you run journalctl -u nameOfUnit or systemctl status nameOfUnit ? I'm running Ubuntu server.
Yup. It is possible that your service is buffering output before actually writing it to the standard error stream. Try attaching to it with strace -e write PID and observe whether it is actually calling write(2, "some message"..., somenumberofbytes).

To approach this from the other direction, try this program:

    import sys, time

    while True:
        print('test out', flush=True)
        print('test error', file=sys.stderr, flush=True)
        time.sleep(5)
With this service:

    [Service]
    Type=simple
    ExecStart=/usr/bin/python3 /tmp/test.py