brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: journalctl _SYSTEMD_SLICE= shows everything one slice logged

Journalctl
~/tips/tip-journalctl-slice

journalctl _SYSTEMD_SLICE=user-1000.slice --since today

Read the logs of every process in one slice, such as one user's session.

systemd puts every process in a slice: services in system.slice, each logged in user in user-UID.slice, template instances in their own sub slice. The journal records that slice with each line.

So one match gives you everything a user’s session produced, from their shell tools to their user services:

journalctl _SYSTEMD_SLICE=user-1000.slice --since today

To see which slices exist in your journal, list the values first:

journalctl -F _SYSTEMD_SLICE

The list can look like -.slice, system.slice and system-hello.slice. That last one is the automatic slice systemd made for the instances of a template called [email protected], which is a neat way to read all instances of one template together.

I like this one on shared boxes where _UID= is too narrow. A user’s session can run things under other IDs through sudo, and those stay in the same slice. Also handy when you put your own services in a custom slice with Slice=batch.slice to limit their resources.

Containers and machines started with systemd-nspawn live in machine.slice, but their own internal logs mostly stay in their own journal, so use -M for those.

Further reading: systemd.journal-fields man page, systemd.slice man page

More Journalctl tips journalctl -k -g 'killed process' --since "2 days ago" journalctl _PID=1 -b ls -lh /var/log/journal/*/*.journal~ Storage=volatile sudo journalctl --setup-keys All Journalctl tips (81) All topics

Link