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

2021-10-23 Thread Stefan Tatschner
On Fri, 2021-10-22 at 08:42 +, DHAIY DHAIY wrote: > But is there a way to insert one string from command-line into > myservice's journal so that it can be seen byjournalctl -u myservice > later Try this: $ echo "foo" | systemd-cat -t foobar Then you can access your string with: $

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

2021-10-22 Thread Mantas Mikulėnas
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

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

2021-10-22 Thread Mantas Mikulėnas
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

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

2021-10-22 Thread DHAIY DHAIY
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?