I have a job to build the android application automatically on a mac machine, and it will output the logs to log files, after some months, the log files are too large, so I want to install the logrotate to backup the old log files every day, and keep the log files for some days.
Install logrotate
brew install logrotate
After install the logrotate with brew, it output the following messages.
To start logrotate now and restart at login:
brew services start logrotate
Or, if you don't want/need a background service you can just run:
/opt/homebrew/opt/logrotate/sbin/logrotate /opt/homebrew/etc/logrotate.conf
Setup logrotate
Create a dir /opt/homebrew/etc/logrotate.d
, and add the logroate file under this folder.
/path/to/your/logs/*.log {
daily
rotate 7
compress
missingok
notifempty
create 640 username groupname
}
Start logrotate service
From help message after install the logrotate from brew, the start command should like:
brew services start logrotate
But when I run the command, the service was in failed status.
After I run the following command I find that the problem is I need crate one more folder.
/opt/homebrew/opt/logrotate/sbin/logrotate /opt/homebrew/etc/logrotate.conf
Error message when start logrotate
error: error creating stub state file /opt/homebrew/var/lib/logrotate.status: No such file or directory
After create the dir /opt/homebrew/var/lib
, the service can start successfully.