How to block the service logs to be written in /var/log or syslogs

Mukesh KumarMukesh Kumar
2 min read

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:

  1. Check your service configuration: You can check the service file (usually located in /etc/systemd/system/ or /lib/systemd/system/) and look for StandardOutput and StandardError directives. Set them to null or journal if you don’t want them to go to syslog:
[Service]
ExecStart=/path/to/your/application
StandardOutput=null
StandardError=null
  1. Check journald Configuration: Ensure that the ForwardToSyslog setting in your /etc/systemd/journald.conf file is set to no. This prevents journald from forwarding logs to syslog.
[Journal]
ForwardToSyslog=no
  1. 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
0
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.