[systemd-devel] Systemd service and structured logging
Jérémy ROSEN
jeremy.rosen at smile.fr
Fri May 3 11:29:17 UTC 2019
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 at thomas-guettler.de> 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 at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
[image: SMILE] <http://www.smile.eu/>
20 rue des Jardins
92600 Asnières-sur-Seine
*Jérémy ROSEN*
Architecte technique
[image: email] jeremy.rosen at smile.fr
[image: phone] +33 6 88 25 87 42
[image: url] http://www.smile.eu
[image: Twitter] <https://twitter.com/GroupeSmile> [image: Facebook]
<https://www.facebook.com/smileopensource> [image: LinkedIn]
<https://www.linkedin.com/company/smile> [image: Github]
<https://github.com/Smile-SA>
[image: Découvrez l’univers Smile, rendez-vous sur smile.eu]
<https://www.smile.eu/fr/publications/livres-blancs/yocto?utm_source=signature&utm_medium=email&utm_campaign=signature>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20190503/b2758ada/attachment.html>
More information about the systemd-devel
mailing list