8

I have several systemd services defined. They log both to disk and also to the systemd journal, which I can monitor using journalctl -n 0 -fu myservice. However, I notice that the logs that I see from the journalctl tail command are often several minutes behind the disk logs. I've confirmed that this is not related to the actual logging configuration used by the daemon, as when I run the daemon manually and it's outputting its logs to standard output on a console, I see the logs immediately.

How can I see log output from journalctl immediately as the service generates it? Either completely unbuffered, or line buffered would be acceptable.

amoe
  • 185
  • 1
  • 9
  • i'm beginning to think that this is not an issue between the service and journald, nor to do with if it's python or java or whatever, but maybe journalctl which seems to follow for a few seconds and then stops. digging deeper before I either answer or file a bug. My initial experiments are between using `StandardOutput=file:/somepath` and `tail`ing that, or using `journalctl -n 0 -fu myservice` – mike Jul 14 '18 at 01:25

1 Answers1

3

Maybe it is a pipe between your daemon and systemd used for logging which is buffered? Possibly this is a duplicate of Output of a python script running as unit is out of order while shells seems unnafected where advice is:

Adding sys.stdout.flush() after write or PYTHONUNBUFFERED environment will solve this problem

Same advice is on Systemd journal not showing python 3 print

jhutar
  • 269
  • 3
  • 7
  • Not actively using this code any longer but it was a Java service using slf4j and logback. There was no shell wrapper. – amoe Jan 09 '18 at 22:21
  • If it is this issue, Java might have similar way of flushing stdout/stderr: https://stackoverflow.com/questions/12945736/buffered-and-unbuffered-streams-in-java – jhutar Jan 09 '18 at 22:49