# Rails logger
# Rails.logger
Always use Rails.logger.{debug|info|warn|error|fatal}
rather than puts
. This allows your logs to fit into the standard log format, have a timestamp and have a level so you choose whether they are important enough to be shown in a specific environment. You can see the separate log files for your application under log/
directory with your rails app environment name. like: development.log
or production.log
or staging.log
You can easily rotating rails production logs with LogRotate.You just have to do small configuration as below
Open /etc/logrotate.conf
with your favourite linux editor vim
or nano
and add the below code in this file at bottom.
/YOUR/RAILSAPP/PATH/log/*.log {
daily
missingok
rotate 7
compress
delaycompress
notifempty
copytruncate
}
So, How It Works This is fantastically easy. Each bit of the configuration does the following:
Running Logrotate Since we just wrote this configuration, you want to test it.
To run logrotate manually, just do: sudo /usr/sbin/logrotate -f /etc/logrotate.conf
That's it.