Getting started with Ruby on RailsRoutingActiveRecordViewsActiveRecord MigrationsRails Best PracticesNaming ConventionsActionCableActiveModelUser Authentication in RailsActiveRecord AssociationsActiveRecord ValidationsActiveRecord Query InterfaceActionMailerRails generate commandsConfigurationI18n - InternationalizationUsing GoogleMaps with RailsFile UploadsCachingActionControllerConfigurationSafe ConstantizeRails 5Authorization with CanCanMongoidGemsChange default timezoneAsset PipelineUpgrading RailsActiveRecord LockingDebuggingConfigure Angular with RailsRails loggerPrawn PDFRails APIDeploying a Rails app on HerokuActiveSupportForm HelpersActiveRecord TransactionsRSpec and Ruby on RailsDecorator patternElasticsearchReact with Rails using react-rails gemRails Cookbook - Advanced rails recipes/learnings and coding techniquesMultipurpose ActiveRecord columnsClass OrganizationShallow RoutingModel states: AASMRails 5 API AutheticationTesting Rails ApplicationsActive JobsRails frameworks over the yearsAdd Admin PanelNested form in Ruby on RailsFactory GirlImport whole CSV files from specific folderTools for Ruby on Rails code optimization and cleanupActiveJobActive Model SerializersRails Engine - Modular RailsSingle Table InheritanceActiveRecord TransactionsTurbolinksFriendly IDSecurely storing authentication keysAuthenticate Api using DeviseIntegrating React.js with Rails Using HyperloopChange a default Rails application enviornmentReserved WordsRails -EnginesAdding an Amazon RDS to your rails applicationPayment feature in railsRails on docker

Rails logger

Other topics

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:

  • daily – Rotate the log files each day. You can also use weekly or monthly here instead.
  • missingok – If the log file doesn’t exist,ignore it
  • rotate 7 – Only keep 7 days of logs around
  • compress – GZip the log file on rotation
  • delaycompress – Rotate the file one day, then compress it the next day so we can be sure that it won’t interfere with the Rails server
  • notifempty – Don’t rotate the file if the logs are empty
  • copytruncate – Copy the log file and then empties it. This makes sure that the log file Rails is writing to always exists so you won’t get problems because the file does not actually change. If you don’t use this, you would need to restart your Rails application each time.

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.

Contributors

Topic Id: 3904

Example Ids: 13595

This site is not affiliated with any of the contributors.