Systemd Journal log from command line to specific namespace

How to log from command line to a specific systemd log namespace?

When using Systemd to start a service, one can give LogNamespace=myNamespace in combination with StandardOutput=journal as part of the configuration in the unit file.

To see the output of this namespace, it is sufficient to call journalctl --namespace=myNamespace to see only output of this namespace.

With systemd-catit is possible to print directly from command line into the journal: echo "Hello Journal!" | systemd-cat

The print "Hello Journal!" does show up in the default (anonymous?) namespace, which is visible with journalctl. It is not within any namespace and not visible when using journalctl --namespace=myNamespace.

To be more specific on the initial question: When looking at journalct -f --namespace=myNamespace, how to make the output of a process started from command line (without systemd, just plain binary) visible in this view?

Something like echo "Hello Journal!" | systemd-cat --log-namespace=myNamespace

I use LogNamespaces to separate different application logs. If this is not the intended use, an answer which explains how to this in another (better) way is also accepted.


first find out the pid of your journald with your namespace.

ps aux|grep jou
root         243  0.0  0.6  56176 26212 ?        Ss   10:06   0:01 /lib/systemd/systemd-journald
root       10214  0.0  0.3  42308 14740 ?        Ss   11:34   0:00 /lib/systemd/systemd-journald DEBUG

our instance is DEBUG next find out what socket that instance uses:

lsof -p 10214 |grep dev-log
systemd-j 10214 root    5u     unix 0x0000000003787334      0t0   61560 /run/systemd/journal.DEBUG/dev-log type=DGRAM

now we are ready to log to the desired namespace:

logger -u /run/systemd/journal.DEBUG/dev-log HAHAHAHA

journalctl --namespace=DEBUG
Jan 22 11:35:46 myportal-deb root[10339]: HAHAHAHA
Jan 22 11:38:50 myportal-deb root[10559]: HAHAHAHA