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/runlogtest
And 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 runlogtest
The 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]: B
Aug 07 14:22:07 localhost.localdomain runlogtest[8742]: A
Aug 07 14:22:07 localhost.localdomain runlogtest[8742]: B
Aug 07 14:22:10 localhost.localdomain runlogtest[8742]: B
Aug 07 14:22:11 localhost.localdomain runlogtest[8742]: A
Aug 07 14:22:13 localhost.localdomain runlogtest[8742]: B
Aug 07 14:22:15 localhost.localdomain runlogtest[8742]: A
Is 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.
ps aux | grep 'bash.*<script name>' | tee -a <your log file>to your apps? This will add the pid to the log file for identification. Similarly, you canechothe output before each app output to CMD.