<div dir="ltr">Thank you <span style="color:rgb(0,0,0);white-space:pre-wrap">Mantas for the details. </span><div>How do you currently get the logs "every few seconds"? </div><div>> 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. <span style="color:rgb(0,0,0);white-space:pre-wrap"><br></span></div><div><br></div><div>Ah, ok so StandardOutput:file:<log_file> will allow the service to open the fd and directly connect it to the service stdout.<br><br>Let me look into journalctl --follow. Any other alternative approaches for the above implementation? <br><br>Thanks again Mantas.<br></div><div><font color="#500050"></font></div><div><font color="#500050"><br></font></div><div><font color="#500050">--</font></div><div><font color="#500050">Arjun</font></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Sep 27, 2021 at 11:39 PM Mantas Mikulėnas <<a href="mailto:grawity@gmail.com">grawity@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Sep 27, 2021 at 1:11 PM Arjun D R <<a href="mailto:drarjun95@gmail.com" target="_blank">drarjun95@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi Folks,<div><br></div><div>Currently we are using systemd-journald for service logging. We run journalctl for a bunch of services and redirect those to the custom log files for every few seconds. This takes up the CPU for that particular time period since we have lot of IO operations as well. We came to know that systemd version v236+ supports direct logging (StandardOutput:file:<log_file>) to the custom log file by the service. I would like to use that facility but we don't get the prefix that we used to get when using the journal. </div><div><br></div><div>Is there a way to prepare a custom patch locally to add the necessary prefix to the stdout before writing to the custom log file? Is that a good idea? Any other suggestions?</div></div></blockquote><div><br></div><div>Probably not easily, as it's not systemd that is writing to the log file – it's your service process itself that directly gets a FD for the log file as its stdout. It's not specifically a "direct logging" feature, but rather just an equivalent to `myservice > log_file`.</div><div><br></div><div>How do you currently get the logs "every few seconds"? Instead of repeated grabbing, have you tried using `journalctl --follow` to monitor logs continuously? This should use far less I/O than repeated `journalctl | tail` which is what it sounds like you're doing. (Wrap in `stdbuf -o0` if necessary.)<br></div><div><br></div><div>Alternatively, set up the traditional rsyslogd or syslog-ng – writing to custom log files is basically what they *do*, and both of them are capable of receiving logs from journald (either by directly monitoring .journal files or by having the messages forwarded via socket).<br></div></div><br>-- <br><div dir="ltr"><div dir="ltr">Mantas Mikulėnas</div></div></div>
</blockquote></div>