<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="gmail_quote"><div dir="ltr" class="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="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="gmail-m_-3445245133184752786appendonsend"></div>
<hr style="display:inline-block;width:98%">
<div id="gmail-m_-3445245133184752786divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><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="gmail_signature"><div dir="ltr">Mantas Mikulėnas</div></div>