When we set up our application on server, we forget to rotate our logs.
What the rotate means here?
if your log size is increasing from some given value than the log will be replaced with a new empty file.
What is use of it?
If we do not rotate our logs, it takes a lot of memory and reach in GBs. It take a lot of useful space and server speed gets slow down after some time. It is junk and need to be clean after some time.
How we can do it?
There are two way to do so
one is set cron and second is there is a logrotate directory in linux so follow the below steps to rotate logs.
- In Linux, run the below command in terminal
cd /etc/logrotate.d
- Create a new file, Write below command
touch hc (hc is rails application name, it can be any name)
- Run the following commands and fill the file with below lines.
sudo vi hc
copy and paste the below lines
/home/likewise-open/ICPL/tarun.garg/apps/holidaycomparisons/log/*.log {
size=20M
daily
rotate 3
compress
delaycompress
missingok
notifempty
create 644 tarun.garg domain^users
}
/home/likewise-open/ICPL/tarun.garg/apps/holidaycomparisons/log/*.log is path to my log directory
- 'rotate 3' signifies that only 3 logs of particular file.
- logfiles can be compressed using the gzip format by specifying 'compress' and 'delaycompress' delays the compression process till the next log rotation. 'delaycompress' will work only if 'compress' option is specified.
- 'missingok' avoids halting on any error and carries on with the next log file.
- 'notifempty' avoid log rotation if the logfile is empty.
- 'create <mode> <owner> <group>' creates a new empty file with the specified properties after log-rotation.
- Daily signifies that check the log daily.
- size signifies the size of the log after which it should be compressed.
No comments:
Post a Comment