10

I've got a system with several daemons running (as systemd units) that output log information to the journal in Arch Linux. I want to direct the journal output of some of those unit files into a separate text file whose location I specify, essentially creating a log file for a subset of units. How can I go about doing that?

8

Seems this is not possible and unwanted by upstream (redirecting stdout/stderr to individual files) see e.g. http://lists.freedesktop.org/archives/systemd-devel/2012-March/004705.html - read the whole thread for more context information how this is intended to work.

What you can do, is either log to syslog, and that way write to individual files. Or the other way around, if the unit calls some program which can write a log itself, then use that to log to a file.

You may also want to take a look at View stdout/stderr of systemd service

What you already can do with your current setup, is use
journalctl -u yourunitname > yourlogfile_for_yourunitname
to direct the whole journal output for your unit "yourunitname" into a file.

On the latter part, you should also take a look at the hints from Lennart from abovementioned mailing list thread:

On recent systemd versions something like systemd-journalctl -o cat _SYSTEMD_UNIT=postgresql.service should create a very simple output that only includes the actual messages and nothing else. You can even pass "-f" and make this live."

EDIT: Actually, for newer systemd versions the command is only journalctl and from what I can tell, the abovementioned long command is the same as journalctl -u yourunitname and you can also -f there to "follow" the output (as in tailf or tail -f).

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.