Skip to content

Instantly share code, notes, and snippets.

@thiagomgo
Forked from pvin/production.rb
Last active January 20, 2020 14:04
Show Gist options
  • Save thiagomgo/4ea7507ab72f12304aa190e558e757a1 to your computer and use it in GitHub Desktop.
Save thiagomgo/4ea7507ab72f12304aa190e558e757a1 to your computer and use it in GitHub Desktop.
Ruby on Rails production log rotation
# Log Rotate by initialising logger from the app
#Way one
# reference : http://ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html#method-c-new
# This one from Atinder Singh https://medium.com/@atinders/easy-log-rotation-with-rails-5-7b8d3c173461
# config/environments/production.rb
Rails.application.configure do
config.logger = Logger.new(config.paths["log"].first, 5, 10.megabytes)
end
# Number of files : 5
# Maximum file size : 10.megabytes
#Way two
# Alternate way with log rotate
# https://gorails.com/guides/rotating-rails-production-logs-with-logrotate
# For log rotation on a daily basis
/var/www/rails/my_app/log/*.log {
daily
missingok
copytruncate
rotate 14
compress
delaycompress
notifempty
}
# For long term log rotation based on log file size
/var/www/rails/my_app/log/*.log {
size 2G
missingok
copytruncate
rotate 7
compress
nodelaycompress
notifempty
dateformat .%Y%m%d
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment