Re: Prefix for direct logging

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Sep 28, 2021, 06:07 Arjun D R <drarjun95@xxxxxxxxx> wrote:
Thank you Mantas for the details.
How do you currently get the logs "every few seconds"?  
> Actually we have a script that will be triggered every 10 seconds. That script will run "journalctl -u <service>" and redirect the output to the respective log file. We will run journalctl for around 40-50 services for every 10 seconds and redirect it to the respective log files. That may be a bad idea, but this is how we are collecting logs as of now. We need to separate the logs for every service and that's why we ended up with this implementation. 

So replace it with 40-50 instances of continuously running `[stdbuf -o0] journalctl -f -u <service>`.

Although syslogd might be easier, since then you'd only need one process doing the monitoring. (I know both syslogds can access journal fields like _SYSTEMD_UNIT, but I don't know how, so usually I just filter by the traditional "program name" and it does the job.)

You could also have a custom daemon that reads from `journalctl -f -o json` and writes to the appropriate text log...



Ah, ok so StandardOutput:file:<log_file> will allow the service to open the fd and directly connect it to the service stdout.

Yes, so if you want timestamps they have to be provided by your service, pretty much like how most services implement direct logging to files. (Probably the only advantage of StandardOutput is that the service doesn't need permissions to /var/log...)

[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux