Ubuntu – systemd on 15.04 won’t log stdout of unit

15.04logloggingstdoutsystemd

I'm currently trying to make a systemd unit as a web server. Currently, my foo.service file looks as follows:

[Unit]
Description=The Foo Web Server

[Service]
Type=simple
ExecStart=/opt/foo/.cabal-sandbox/bin/foo

[Install]
WantedBy=multi-user.target

The foo executable automatically logs all HTTP requests to stdout – this is well tested. However, when I view the logs with journalctl -u foo, I only get output like this:

...
May 06 17:46:57 localhost systemd[1]: Stopping The Foo Web Server...
May 06 17:46:57 localhost systemd[1]: Started Foo Web Server.
May 06 17:46:57 localhost systemd[1]: Starting The Foo Web Server...
May 06 17:47:08 localhost systemd[1]: Stopping The Foo Web Server...
May 06 17:47:08 localhost systemd[1]: Started The Foo Web Server.
May 06 17:47:08 localhost systemd[1]: Starting The Foo Web Server...

Could someone explain why it's not logging all stdout output? I looked briefly at this previous question, but it doesn't help – however it alluded to something along the lines of "…may not work for systems that don't use full systemd" – would this be the case for Ubuntu 15.04? Thank you in advance, any help with this would be much appreciated!

Best Answer

In fact, buffering in UNIX depends on the context: when stdout is redirected to something interactive like a console - it is usually line-buffered, otherwise it is fully buffered.

Buffering may be changed inside the application using setvbuf library call.

But it can also be done with stdbuf command on launch:

ExecStart=/usr/bin/stdbuf -oL /opt/foo/.cabal-sandbox/bin/foo

(for line-buffered case)

Related Question