Skip to content

Instantly share code, notes, and snippets.

@mattyoho
Forked from travisvalentine/logrotate.markdown
Created June 1, 2012 13:37
Show Gist options
  • Save mattyoho/2852202 to your computer and use it in GitHub Desktop.
Save mattyoho/2852202 to your computer and use it in GitHub Desktop.
Logrotate

Install

brew install logrotate

add to .bash_profile

export PATH=${PATH}:/usr/local/sbin

restart terminal just to check the logrotate command returns something

logrotate -?

make logrotate.d directory inside of /etc/ and add new config file

(I made mine feed_engine)

create conf file for app

/Users/travisvalentine/hungry-projects/feed_engine/log/*.log {    (So logrotate knows which files to rotate.)
  size 0k                                                         (Logrotate runs only if the filesize is equal to (or greater than) this size.)
  missingok                                                       (Don’t issue an error message if log files are missing.)
  rotate 7                                                        (The maximum number of log files to keep. Once you have more, oldest deleted.)
  mail [email protected]                         (email me the log files)
  compress                                                        (Compress old versions of log files to save space (uses gzip by default))
  delaycompress                                                   (Delays the compression until the next log rotation.)
  notifempty                                                      (Won't rotate if the log file is empty.)
  copytruncate                                           (Makes a backup copy of the current log and then clears the log file for continued writing.)
}

force logrotate to run

logrotate -f <configfile> (In my case, logrotate -f feed_engine)

@broofa
Copy link

broofa commented Aug 15, 2017

Also, sudo brew services start logrotate to run as daemon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment