Logfile Management
When running an active production site, log files can quickly spiral out of control to consume all available disk space. Your Boxcar is already configured to handle most log files for you, but here are some best practices to keep in mind.
Store nginx access logs in /var/log/nginx/
In a shared environment, users are used to keeping everything within their home directory. Since the Boxcar is yours and yours alone, feel free to spread out and use the system directories as intended.
Nginx is pre-configured to rotate all logs in the /var/log/nginx/ directory that end in .log. You can set the location of your access and error logs in your nginx configuration. By default, this is at:
/etc/nginx/sites-enabled/mongrel
Look for the access_log directive and point it to:
/var/log/nginx/SITENAME.log (replacing SITENAME with the name of your site)
Set up a custom logrotate configuration for your application
Once your application is deployed, you should consider setting up a custom logrotate rule to handle your production.log. All system-wide logrotate scripts are stored in /etc/logrotate.d/.
productionlogs, and paste the following into it:
/home/DEPLOYMENT_USER/sites/APPLICATION_NAME/shared/log/production.log {
size 1G
rotate 4
compress
copytruncate
notifempty
}
Don’t forget to substitute DEPLOYMENT_USER and APPLICATION_NAME for the actual name of your deployment user and the name of your application, respectively. You can customize the above parameters to your liking. This configuration will rotate the logs once they reach 1 GB in size, and keep 4 backup copies. All backups will be compressed so they will take up considerably less space.
You can change the size to any value you’d like. Use “G” for gigabytes, and “M” for megabytes. You can also rotate the logs daily by removing size 1G and putting daily in its place.
The rotate 4 line tells it to keep 4 compressed logs from the rotation. If you’d like to keep logs going further back you can change this value. A common option is to set the logs to rotate daily, and then keep 30, 60, or 90 backups to give you 1, 2, or 3 months worth of log data, respectively.