[systemd-devel] Systemd service and structured logging

Thomas Güttler guettliml at thomas-guettler.de
Fri May 3 09:09:21 UTC 2019


I have a systemd service which is of type "simple".

I want my service to log key-value pairs.

Is there a way to use structured logs with systemd?

For example my service writes this to stdout:

{"key1": "value1", "key2": 1234}
{"key1": "value2", "key2": 5678}
...


It would be great of systemd could read the string as json.

Related question at StackO: https://stackoverflow.com/questions/55806921/systemd-service-and-structured-logging

I see two ways:

V1: my logs get stored in journald as message (as plain string).

V2: my key-value pairs get stored in the journald key-value dictionary.

What do you suggest?

Background: I don't want an ELK stack. I want a simple solution. Since
journald already has key-value pairs for a log entry, why not use it?


-- 
Thomas Guettler http://www.thomas-guettler.de/
I am looking for feedback: https://github.com/guettli/programming-guidelines


More information about the systemd-devel mailing list