How to limit the size of syslog to save storage space

Now I just had an issue with LibreWolf spewing errors like no tomorrow and filling up my syslog file to a whooping file size of over 200GB.

As shown in the picture you can find your syslog file under /var/log. Here's how can get started on limiting the file size of the syslog. Open your terminal and run this command so we can edit rsyslog which is a file that deals with how syslog is handled. This doesn't limit the file of syslog but the size of the rotating files.

sudo gedit /etc/logrotate.d/rsyslog

Edit it like so and add in size 100k.

Make sure to save by either clicking on save or press ctrl+s before exiting. Now to limit the current syslog file. Run this command so we can set a fixed log size.

sudo gedit /etc/rsyslog.d/50-default.conf

We are going to make two edits in this file. Above *.*;auth,authpriv.none -/var/log/syslog we are going to create a channel thats limited to a 1MB called mysyslog. Don't worry this won't affect the actual file name. Copy and paste this in the file as shown below.

$outchannel mysyslog,/var/log/syslog,1048576

Next we are going to make syslog use that channel like so.
Before: *.*;auth,authpriv.none -/var/log/syslog

After: *.*;auth,authpriv.none :omfile:$mysyslog

After saving the file run this to restart the rsyslogd.

sudo systemctl restart rsyslog.service

You can check if it's running properly by running this command.

systemctl status rsyslog.service

If you still have a big file like me though you probably want to remove it now so lets stop our rsyslog.service so we can remove it. Run this to stop the service.

sudo systemctl stop rsyslog.service

Now just copy and paste this. You really don't want to mess up when deleting something with sudo as it's like a loaded gun. Last thing you want to do is shoot yourself in the foot.

sudo rm /var/log/syslog

Now lets start the service up again running this command.

sudo systemctl start rsyslog.service

Once again we can run this command to see if the service is running.

systemctl status rsyslog.service

Here is my source.
https://askubuntu.com/questions/184949/how-do-i-limit-the-size-of-my-syslog

4 Likes