I intend to log a python script output.
Here what it looks like :
arm@stackoverflow > cat test.py
#!/usr/bin/python
from time import sleep
while True:
print("Hello")
sleep(1)
I try to use standard syslog way to handle logs, I therefore tried to configure JournalD & SystemD to send everything as Syslog
:
arm@stackoverflow > cat /etc/systemd/journald.conf | grep -vP "^#"
[Journal]
ForwardToSyslog=yes
arm@stackoverflow > cat /etc/systemd/system/testservice.service
[Unit]
Description="Test service"
StartLimitIntervalSec=500
StartLimitBurst=10
[Service]
Type=Simple
Restart=on-failure
RestartSec=5s
ExecStart=/home/pi/test.py
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=testservice
[Install]
WantedBy=multi-user.target
Finally I use Debian's default Rsyslog to route my logs in some file:
arm@stackoverflow > tail -n1 /etc/rsyslog.conf
if $programname == 'testservice' then /var/log/testservice.log
arm@stackoverflow > sudo touch /var/log/testservice.log && sudo chmod a+rw /var/log
But when I start the whole, all logs seems to be clogged somewhere, and are releases at one hours after start (like a big despool):
arm@stackoverflow > sudo systemctl start testservice.service && sleep 30
Then:
arm@stackoverflow > tail /var/log/testservice.log #nothing
Tests:
arm@stackoverflow > sudo systemctl status testservice.service
● testservice.service - "Test service"
Loaded: loaded (/etc/systemd/system/testservice.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2023-02-21 09:20:06 CET; 1min 33s ago
arm@stackoverflow > ps aux | grep test
root 23488 0.0 0.6 13956 5968 ? Ss 09:20 0:00 /usr/bin/python /home/pi/test.py
Do you know how to get these logs in realtime?
Misc. This is a test server on Raspberry Pi OS (ARM)