<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Thanks a lot Mantas.</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
But in my sytem, logger does not have "--journal".</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Are you aware of other tools from bash which can be used?</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
BR<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>发件人:</b> Mantas Mikulėnas <grawity@gmail.com><br>
<b>发送时间:</b> 2021年10月22日 18:45<br>
<b>收件人:</b> DHAIY DHAIY <dhaiy@msn.com><br>
<b>抄送:</b> systemd-devel@lists.freedesktop.org <systemd-devel@lists.freedesktop.org><br>
<b>主题:</b> Re: [systemd-devel] 回复: Is it possible to send a string to the journal of one specific systemd unit</font>
<div> </div>
</div>
<div>
<div dir="ltr">If you have root privileges (i.e. UID 0), then yes, you can send a journal message with the "OBJECT_SYSTEMD_UNIT=myservice.service" field and journalctl will automatically look for that.
<div><br>
</div>
<div>In C, specify the field when calling sd_journal_sendv(); in bash you can use `logger --journal`:</div>
<div><br>
</div>
<div><font face="monospace">(echo "OBJECT_SYSTEMD_UNIT=sshd.service";<br>
 echo "MESSAGE=Hello world!") | sudo logger --journal</font><br>
</div>
</div>
<br>
<div class="x_gmail_quote">
<div dir="ltr" class="x_gmail_attr">On Fri, Oct 22, 2021 at 11:43 AM DHAIY DHAIY <<a href="mailto:dhaiy@msn.com">dhaiy@msn.com</a>> wrote:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<p>Saying we have a systemd unit named "myservice". <br>
</p>
<p>we can use <strong>journalctl -u myservice</strong> to inspect the logs generated by myservice.</p>
<p><br>
</p>
<p>But is there a way to insert one string from command-line into myservice's journal so that it can be seen by
<strong>journalctl -u myservice</strong> later?</p>
</div>
<br>
</div>
<div id="x_gmail-m_-3445245133184752786appendonsend"></div>
<hr style="display:inline-block; width:98%">
<div id="x_gmail-m_-3445245133184752786divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>发件人:</b> DHAIY DHAIY<br>
<b>发送时间:</b> 2021年10月22日 16:40<br>
<b>收件人:</b> <a href="mailto:systemd-devel@lists.freedesktop.org" target="_blank">
systemd-devel@lists.freedesktop.org</a> <<a href="mailto:systemd-devel@lists.freedesktop.org" target="_blank">systemd-devel@lists.freedesktop.org</a>><br>
<b>主题:</b> Is it possible to send a string to the journal of one specific systemd unit</font>
<div> </div>
</div>
<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>
<p>Saying we have a systemd unit named "myservice". <br>
</p>
<p>we can use <strong>journalctl -u myservice</strong> to inspect the logs generated by myservice.</p>
<p><br>
</p>
<p>But is there a way to insert one string from command-line into myservice's journal so that it can be seen by
<strong>journalctl -u myservice</strong> later?</p>
</div>
<br>
</div>
</div>
</div>
</blockquote>
</div>
<br clear="all">
<div><br>
</div>
-- <br>
<div dir="ltr" class="x_gmail_signature">
<div dir="ltr">Mantas Mikulėnas</div>
</div>
</div>
</body>
</html>