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 <dh...@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@lists.freedesktop.org <
> systemd-devel@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

Reply via email to