[systemd-devel] Systemd service and structured logging

Lennart Poettering lennart at poettering.net
Mon May 6 14:09:10 UTC 2019

On Fr, 03.05.19 11:09, Thomas G├╝ttler (guettliml at thomas-guettler.de) wrote:

> 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?

Depend on your programming language.

In C, sd_journal_send()/sd_journal_sendv() is the API of choice.


That said, there are other C APIs that speak the same protocol. For
example, glib's logging logic will magically use systemd's native
logging protocol if it is available.

If you use a different programming language, there are bindings for
the same protocol for various languages around (including python).

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

JSON is complex to index properly. systemd supports a simpler
"environment-variable-like" format instead. For details see link


Lennart Poettering, Berlin

More information about the systemd-devel mailing list