Re: Systemd service and structured logging

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



if you want the whole power of structured logs, you need to use the journald API
I am not sure in what language your program is written, but if you are using C, it's pretty trivial to do
(and i'm pretty sure most bindings are trivial to use too)

Automated parsing of stdout is limited, you can 
* add a (constant) key=value to all messge
* automatically parse a "<x>" prefix and transform that into a message gravity
and that's pabasically it. for anything more complex, you need to go through the journald API

Le ven. 3 mai 2019 à 11:14, Thomas Güttler <guettliml@xxxxxxxxxxxxxxxxxx> a écrit :
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
_______________________________________________
systemd-devel mailing list
systemd-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


--
SMILE 

20 rue des Jardins
92600 Asnières-sur-Seine

Jérémy ROSEN
Architecte technique

email jeremy.rosen@xxxxxxxx 
phone  +33 6 88 25 87 42 
url http://www.smile.eu

Twitter Facebook LinkedIn Github

Découvrez l’univers Smile, rendez-vous sur smile.eu
_______________________________________________
systemd-devel mailing list
systemd-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/systemd-devel

[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux