On Fr, 23.03.18 12:52, Filipe Brandenburger (filbran...@google.com) wrote:

> Hi!
> 
> So I'm testing a program repeatedly and using `systemd-run` to start a
> service with it, passing it a specific unit name.
> 
> When the test finishes and I bring down the service, I want to be able to
> collect the journald logs for that execution of the test alone.
> 
> Right now what I'm doing is naming the service differently every time,
> including a random number, so I can collect the logs for that service alone
> at the end. Such as:

What you are looking for is the "invocation ID". It's a 128bit random
UUID unique for each invocation cycle of a service (i.e it's generated
fresh whenever a unit enters the STARTING phase). It's included in the
service's env block (as well as the keyring and attached to its
cgroup). The journal will also attach it to every log message of the
service.

systemd-run currently doesn't show you the invocation ID however, but
I figure this is something we should really fix. 

> I guess what I'm looking for is a way to get systemd to inject a journal
> field to every message logged by my unit. Something like an environment
> variable perhaps? Or some other field I can pass to systemd-run using -p.
> Or something that systemd itself generates, that's unique for each
> execution of the service and that I can query somehow (perhaps `systemd
> show` while the service is up.) Is there any such thing?

You can also use "-p LogExtraFields=QUUX=miep" to attach arbitrary
additional journal fields to all log messages of the service you run
that way.

Lennart

-- 
Lennart Poettering, Red Hat
_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to