I have a systemd service which starts multiple 3rd-party processes which output to standard output. Is there anyway to easily determine which logs are from specific process from the system journal?Diving into systemd recently, I had a question about logging. man systemd-journald.service notes that:It creates and maintains structured, indexed journals based on logging information that is received from the kernel, from user processes via the libc syslog(3) call, from standard input and standard error of system services or via its native API.I created a simple service:[Service]ExecStart=/home/myself/logtest/runlogtestAnd have the script invoke some processes:#!/bin/bash.../home/myself/logtest/app1 &/home/myself/logtest/app2 &...When the service is running, I listen for messages using the following command:journalctl -f | grep runlogtestThe output is seen as the following (for this example, app1 output 'A' and app2 output 'B'):Aug 07 14:22:04 localhost.localdomain runlogtest[8742]: BAug 07 14:22:07 localhost.localdomain runlogtest[8742]: AAug 07 14:22:07 localhost.localdomain runlogtest[8742]: BAug 07 14:22:10 localhost.localdomain runlogtest[8742]: BAug 07 14:22:11 localhost.localdomain runlogtest[8742]: AAug 07 14:22:13 localhost.localdomain runlogtest[8742]: BAug 07 14:22:15 localhost.localdomain runlogtest[8742]: AIs there anyway to know that 'A' logs are coming from app1 (and 'B' messages are from app2)?The only solutions I can see right now is that I would:Manage each application in its own service (something I'd like to avoid).Make a wrapper for process which I capture their standard output and pump to the journal via syslog.
How to determine a log's source process spawned from a systemd service?
systemd;journald
Make a wrapper for process which I capture their standard output and pump to the journal via syslog.Such wrapper already exists and is called systemd-cat.You may use it as follows:systemd-cat -t app1 /home/myself/logtest/app1 &systemd-cat -t app2 /home/myself/logtest/app2 &The argument to -t is an arbitrary identification string, analogous (equivalent) to syslog's identifier.It is also possible to use systemd-cat in a shell pipeline like this:/home/myself/logtest/app1 |& systemd-cat -t app1 &(The |& is a bash construction to pipeline both stdout and stderr.)However, the first form is preferable as it avoids spawning an extra process and doing an extra copy of all logged data.