[systemd-devel] 回复: 回复: Is it possible to send a string to the journal of one specific systemd unit

DHAIY DHAIY dhaiy at msn.com
Sat Oct 23 05:33:32 UTC 2021


python works fine!
Thanks a lot, Mantas.

BR.
________________________________
发件人: Mantas Mikulėnas <grawity at gmail.com>
发送时间: 2021年10月23日 6:42
收件人: DHAIY DHAIY <dhaiy at msn.com>
抄送: systemd-devel at lists.freedesktop.org <systemd-devel at lists.freedesktop.org>
主题: Re: [systemd-devel] 回复: Is it possible to send a string to the journal of one specific systemd unit

This option was added with util-linux v2.25 in 2014. If you're using an older version or the Busybox `logger` instead, well, it won't have that.

The alternative is to write your own C tool that uses libsystemd and calls sd_journal_send<https://manpages.debian.org/testing/libsystemd-dev/sd_journal_send.3.en.html>() with the correct fields (libsystemd is definitely going to be present), or a Python tool that uses systemd.journal.send(). (Or maybe call libsystemd through python ctypes or whatever other FFI mechanism is available.)



On Fri, Oct 22, 2021 at 4:32 PM DHAIY DHAIY <dhaiy at msn.com<mailto:dhaiy at msn.com>> wrote:
Thanks a lot Mantas.
But in my sytem, logger does not have "--journal".
Are you aware of other tools from bash which can be used?

BR
________________________________
发件人: Mantas Mikulėnas <grawity at gmail.com<mailto:grawity at gmail.com>>
发送时间: 2021年10月22日 18:45
收件人: DHAIY DHAIY <dhaiy at msn.com<mailto:dhaiy at msn.com>>
抄送: systemd-devel at lists.freedesktop.org<mailto:systemd-devel at lists.freedesktop.org> <systemd-devel at lists.freedesktop.org<mailto:systemd-devel at lists.freedesktop.org>>
主题: Re: [systemd-devel] 回复: Is it possible to send a string to the journal of one specific systemd unit

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.

In C, specify the field when calling sd_journal_sendv(); in bash you can use `logger --journal`:

(echo "OBJECT_SYSTEMD_UNIT=sshd.service";
 echo "MESSAGE=Hello world!") | sudo logger --journal

On Fri, Oct 22, 2021 at 11:43 AM DHAIY DHAIY <dhaiy at msn.com<mailto:dhaiy at msn.com>> wrote:

Saying we have a systemd unit named "myservice".

we can use journalctl -u myservice to inspect the logs generated by myservice.


But is there a way to insert one string from command-line into myservice's journal so that it can be seen by journalctl -u myservice later?

________________________________
发件人: DHAIY DHAIY
发送时间: 2021年10月22日 16:40
收件人: systemd-devel at lists.freedesktop.org<mailto:systemd-devel at lists.freedesktop.org> <systemd-devel at lists.freedesktop.org<mailto:systemd-devel at lists.freedesktop.org>>
主题: Is it possible to send a string to the journal of one specific systemd unit


Saying we have a systemd unit named "myservice".

we can use journalctl -u myservice to inspect the logs generated by myservice.


But is there a way to insert one string from command-line into myservice's journal so that it can be seen by journalctl -u myservice later?



--
Mantas Mikulėnas


--
Mantas Mikulėnas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20211023/b270c7eb/attachment.htm>


More information about the systemd-devel mailing list