Skip to content

Instantly share code, notes, and snippets.

@psahni
Last active February 18, 2016 19:28
Show Gist options
  • Save psahni/2209b8a0cfa861e6cd03 to your computer and use it in GitHub Desktop.
Save psahni/2209b8a0cfa861e6cd03 to your computer and use it in GitHub Desktop.
Rails Production with logging

Ruby in Production: Lessons Learned

https://medium.com/@rdsubhas/ruby-in-production-lessons-learned-36d7ab726d99

How to run application as service and managing logging in production

  • Install foreman gem to manage processes

    Procfile

    web: rails server

  • Type following command from inside the project directory:-

  $ sudo foreman export --app app_name --user prashant upstart /etc/init

  $ ls /etc/init/app_name*

  $ ls /var/log/app_name/

In this way out app is on par with a core system service. We don’t have to dabble with PID files, system handles that. The OS will automatically reboot service if it crashes, rotate logs.

More info: http://stackoverflow.com/questions/12990842/how-to-use-foreman-to-export-to-upstart

rails_12factor gem

  1. This gem redirects log in production to stdout, from there we can manage the log through OS or use any log aggregation service like papertrail gem.

  2. It enables rails app server to serve static assets which is actually giving more control to rails app server. This is usually managed through reverse proxy server like Ngnix/Apache.

It basically enables this flag config.serve_static_assets = true

12 factor App

http://12factor.net/

Ruby (and Rails) deployment kickstart with dotEnv, Foreman, Ansible, Docker and Vagrant

https://github.com/rdsubhas/ruby-deploy-kickstart

Better Rails logging

https://pooreffort.com/blog/better-rails-logging/

Lograge gem

Improved Rails logging - very nice gem https://github.com/roidrage/lograge

How to enable lograge ?

  unless Rails.env.test?
      log_level = String(ENV['LOG_LEVEL'] || "info").upcase
      config.logger = Logger.new(STDOUT)
      config.logger.level = Logger.const_get(log_level)
      config.log_level = log_level
      #config.lograge.enabled = true # see lograge section below...
    end

Foreman gem

http://ddollar.github.io/foreman/

Log rotation

http://stackoverflow.com/questions/4883891/ruby-on-rails-production-log-rotation

More on Production logging

http://rubyjunky.com/cleaning-up-rails-4-production-logging.html

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