How to block the service logs to be written in /var/log or syslogs
systemd is a system and service manager for Linux operating systems. It was designed to replace older init systems like System V and Linux Standard Base init.
If your application is running as a systemd service, ensure that the service file does not redirect logs to syslog. You can open syslog and can see the live logs which are being added to the file using below command:
sudo tail -f /var/log/syslog
Follow these 3 steps:
- Check your service configuration: You can check the service file (usually located in
/etc/systemd/system/
or/lib/systemd/system/
) and look forStandardOutput
andStandardError
directives. Set them tonull
orjournal
if you don’t want them to go to syslog:
[Service]
ExecStart=/path/to/your/application
StandardOutput=null
StandardError=null
- Check journald Configuration: Ensure that the
ForwardToSyslog
setting in your/etc/systemd/journald.conf
file is set tono
. This preventsjournald
from forwarding logs to syslog.
[Journal]
ForwardToSyslog=no
- Reload systemd and Restart Service: After making changes, reload the systemd manager configuration and restart your service.
sudo systemctl daemon-reload
sudo systemctl restart your-service-name
After step 3 your logs should have stopped to capture in syslog.
Option Step:
Log Level Configuration: If you still see logs in syslog, you might want to set the MaxLevelSyslog
in journald.conf
to a higher level (e.g., warning
) to filter out lower-level messages.
[Journal]
MaxLevelSyslog=warning
Subscribe to my newsletter
Read articles from Mukesh Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Mukesh Kumar
Mukesh Kumar
I am a Software Development lead in a product based company.