Manjaro Difference between revisions of "Limit the size of .log files & the journal"

Difference between revisions of "Limit the size of .log files & the journal"

From Manjaro
imported>Handy
imported>Handy
Line 28: Line 28:


<br clear="all"/>
<br clear="all"/>
= How to set maximum log file size =
= Handling /var/log/*.log files =


Note: This section is set to be expanded soon.
== Introducing Logrotate & friends ==


This is as simple as the previous example for the journal, this time the file we edit (with root priviliges also) is '''/etc/logrotate.conf''' .
'''/etc/logrotate.conf''' holds general settings for the '''/usr/bin/logrotate''' command that are applied to ''some'' of the /var/log/ files.


You'll find these two lines (without the 10M which is the current limit that I have set on my machine):
'''logrotate''' is called however often it is set to be called. Meaning, it can be called from any of the following directories that reside in '''/etc/''' ''cron.hourly'', ''cron.daily'', ''cron.weekly'', ''cron.monthly'', ''cron.yearly'', by placing a script that calls it into any of these previously mentioned directories. (All of which bar the cron.yearly exist by default in Manjaro.)


  #restrict maximum size of log files
Logrotate can also be called to run at any time via '''crontab''' .
  size 10M
 
The logrotate.conf , as well as whatever commands it contains, also runs any scripts that are located in the '''/etc/logrotate.d''' which it does via the following command:
 
  include /etc/logrotate.d
 
Some installed applications drop scripts into /etc/logrotate.d to aid in their own maintenance one way or another. We can use another location of our choosing for these or other scripts if we want, we just have to call its path the same way, as in the following is an example:
 
include /home/handy/.config/mylogrotate
 
Apart from adding our own scripts to /etc/logrotate.d (or any other path that we have included, we can also add scripts into the previously mentioned /etc/ cron.hourly, cron.daily, cron.weekly, cron.monthly, folders.
 
So you can see there are multiple ways to call logrotate.
 
<br clear="all"/>
== Some uses for Logrotate ==
 
For example, if we wanted to rotate a particular log file in our /var/log/ directory on a daily basis; keep it for 7 days before it is deleted (meaning there would be 7 separate log files for the week); compress the file but do it on the next cycle; do it in a fashion where the original contents of the file is copied before the original file's contents is deleted; do nothing if the file is empty; if the file is missing don't give an error; we should be able to do that with the following:
 
 
  /var/log/*.log {
  daily
  rotate 7
  compress
  delaycompress
  copytruncate
  notifempty
  missingok
  }
 
 
Now if we put the previous into a script by itself, or with other similar blocks of code that have been tailored to suit different files contained in /var/log/ , into the /etc/logrotate.d/ directory & we have /etc/logrotate.conf being called daily, then logrotate.conf will run any scripts that we have in logrotate.d everyday for us thus our log files will be rotated as we have instructed.


<br clear="all"/>
<br clear="all"/>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.