22

I have a running systemd unit and I want to follow it's log.

I know I can show unit's log by using:

journalctl -u my_unit.service

But that only prints current logs without following them.

I know I can also follow systemd logs by using:

journalctl -f

But that spams the output by following all known logs, so I have to search for what I'm interested in.

A temporary solution seems to be piping followed logs to grep filtering the output, but that's not very systematic solution:

journalctl -f | grep "what i'm interested in"

Isn't there a command for following logs of certain unit?

What I've tried, but didn't work:

journalctl -uf my_unit.service

1 Answer 1

37

I've found out I'm using the arguments in a bad order. Logs can actually be followed for a single unit by using:

journalctl -fu my_unit.service

Other working variations:

journalctl -f -u my_unit.service
journalctl -u my_unit.service -f

From journalctl manual:

-u, --unit=UNIT|PATTERN

    Show messages for the specified systemd unit UNIT (such as a service unit), or for any of the units matched by PATTERN. If a pattern is specified, a list of unit names found in the journal is compared with the specified pattern and all that match are used.  For each unit name, a match is added for messages from the unit ("_SYSTEMD_UNIT=UNIT"), along with additional matches for messages from systemd and messages about coredumps for the specified unit.

    This parameter can be specified multiple times.

-f, --follow

    Show only the most recent journal entries, and continuously print new entries as they are appended to the journal.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.