<div dir="ltr">if you want the whole power of structured logs, you need to use the journald API<div>I am not sure in what language your program is written, but if you are using C, it's pretty trivial to do</div><div>(and i'm pretty sure most bindings are trivial to use too)</div><div><br></div><div>Automated parsing of stdout is limited, you can </div><div>* add a (constant) key=value to all messge</div><div>* automatically parse a "<x>" prefix and transform that into a message gravity</div><div>and that's pabasically it. for anything more complex, you need to go through the journald API</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le ven. 3 mai 2019 à 11:14, Thomas Güttler <<a href="mailto:guettliml@thomas-guettler.de">guettliml@thomas-guettler.de</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I have a systemd service which is of type "simple".<br>
<br>
I want my service to log key-value pairs.<br>
<br>
Is there a way to use structured logs with systemd?<br>
<br>
For example my service writes this to stdout:<br>
<br>
{"key1": "value1", "key2": 1234}<br>
{"key1": "value2", "key2": 5678}<br>
...<br>
<br>
<br>
It would be great of systemd could read the string as json.<br>
<br>
Related question at StackO: <a href="https://stackoverflow.com/questions/55806921/systemd-service-and-structured-logging" rel="noreferrer" target="_blank">https://stackoverflow.com/questions/55806921/systemd-service-and-structured-logging</a><br>
<br>
I see two ways:<br>
<br>
V1: my logs get stored in journald as message (as plain string).<br>
<br>
V2: my key-value pairs get stored in the journald key-value dictionary.<br>
<br>
What do you suggest?<br>
<br>
Background: I don't want an ELK stack. I want a simple solution. Since<br>
journald already has key-value pairs for a log entry, why not use it?<br>
<br>
<br>
-- <br>
Thomas Guettler <a href="http://www.thomas-guettler.de/" rel="noreferrer" target="_blank">http://www.thomas-guettler.de/</a><br>
I am looking for feedback: <a href="https://github.com/guettli/programming-guidelines" rel="noreferrer" target="_blank">https://github.com/guettli/programming-guidelines</a><br>
_______________________________________________<br>
systemd-devel mailing list<br>
<a href="mailto:systemd-devel@lists.freedesktop.org" target="_blank">systemd-devel@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/systemd-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/systemd-devel</a></blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><table border="0" style="border-collapse:collapse;border-spacing:0px;color:rgb(51,51,51);font-family:Raleway,regular;font-size:14px;padding:20px"><tbody><tr><td style="padding:0px 30px 0px 0px;font-size:13px;color:rgb(255,128,84);text-align:center"><a href="http://www.smile.eu/" style="background-color:transparent;color:rgb(221,72,20)" target="_blank"><img src="http://ftp.smile.fr/client/Communication/signature/img/Logo-new.png" alt="SMILE" style="border: 0px; vertical-align: middle; max-width: 100%; height: auto;"> </a><br><br><p style="margin:0px 0px 10px">20 rue des Jardins<br>92600 Asnières-sur-Seine</p></td><td style="padding:0px 0px 0px 20px;border-left:1px solid rgb(59,127,254);font-size:13px;color:rgb(255,128,84)"><div style="font-size:14px"><b>Jérémy ROSEN</b></div><div style="color:rgb(59,127,254)">Architecte technique<br></div><br><div style="color:rgb(59,127,254)"><span style="white-space:nowrap"><img src="http://ftp.smile.fr/client/Communication/signature/img/mail.png" alt="email" width="12" height="10" style="border: 0px; vertical-align: middle; margin-right: 5px;"> <a href="mailto:jeremy.rosen@smile.fr" style="background-color:transparent;color:rgb(59,127,254)" target="_blank">jeremy.rosen@smile.fr</a> </span><br><span style="white-space:nowrap"><img src="http://ftp.smile.fr/client/Communication/signature/img/phone.png" alt="phone" width="10" height="10" style="border: 0px; vertical-align: middle; margin-right: 5px;"></span> +33 6 88 25 87 42 <br><span style="white-space:nowrap"><img src="http://ftp.smile.fr/client/Communication/signature/img/web.png" alt="url" width="12" height="12" style="border: 0px; vertical-align: middle; margin-right: 5px;"> <a href="http://www.smile.eu/" style="background-color:transparent;color:rgb(59,127,254)" target="_blank">http://www.smile.eu</a></span></div><br><div><span><a href="https://twitter.com/GroupeSmile" style="background-color:transparent;color:rgb(221,72,20);margin-right:5px" target="_blank"><img src="http://ftp.smile.fr/client/Communication/signature/img/rs-twitter.png" alt="Twitter" style="border: 0px; vertical-align: middle; max-width: 100%; height: auto;"></a></span> <span><a href="https://www.facebook.com/smileopensource" style="background-color:transparent;color:rgb(221,72,20);margin-right:5px" target="_blank"><img src="http://ftp.smile.fr/client/Communication/signature/img/rs-facebook.png" alt="Facebook" style="border: 0px; vertical-align: middle; max-width: 100%; height: auto;"></a></span> <span><a href="https://www.linkedin.com/company/smile" style="background-color:transparent;color:rgb(221,72,20);margin-right:5px" target="_blank"><img src="http://ftp.smile.fr/client/Communication/signature/img/rs-linkedin.png" alt="LinkedIn" style="border: 0px; vertical-align: middle; max-width: 100%; height: auto;"></a></span> <span><a href="https://github.com/Smile-SA" style="background-color:transparent;color:rgb(221,72,20);margin-right:5px" target="_blank"><img src="http://ftp.smile.fr/client/Communication/signature/img/rs-github.png" alt="Github" style="border: 0px; vertical-align: middle; max-width: 100%; height: auto;"></a></span></div></td></tr></tbody></table><br style="color:rgb(51,51,51);font-family:Raleway,regular;font-size:14px"><div style="color:rgb(51,51,51);font-family:Raleway,regular;font-size:14px"><a href="https://www.smile.eu/fr/publications/livres-blancs/yocto?utm_source=signature&utm_medium=email&utm_campaign=signature" style="background-color:transparent;color:rgb(221,72,20)" target="_blank"><img src="https://signature.smile.eu/assets/img/bandeaux_signature_mail_yocto.gif.gif" alt="Découvrez l’univers Smile, rendez-vous sur smile.eu" border="0" style="border: 0px; vertical-align: middle;"></a></div></div></div></div></div>