gshaw / concise_logging

Alternate logging for Rails production servers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Heroku setup

leonelgalan opened this issue · comments

Hey guys, this is a great Idea, but I haven't been able to set it up on Heroku. I'm trying on my staging server and my staging.rb has the following:

# See everything in the log (default is :info)
# Configure logger to log warn and above
# See https://github.com/gshaw/concise_logging
config.log_level = :warn
config.log_tags = [Rails.env[0]]
config.logger = TaggedLogging.new(Logger.new(STDOUT))
config.logger.level = Logger.const_get(config.log_level.to_s.upcase)

And my Gemfile:

gem 'concise_logging', group: :production

I'm doing STDOUT to conform with https://github.com/heroku/rails_12factor#rails-4-logging, but I might be having conflicts with _ rails_stdout_logging_.

This should be compatible with Heroku logging but my apps aren't deployed there so I haven't looked into it. If you come up a with a fix please post here.

Thanks, it was indeed a conflict with rails_stdout_loging. 404 shows correctly but are followed by a stack trace. RoutingError (also 404s) aren't shown in the concise_logging format, just the stacktrace:

May 29 09:22:59 sushi-app-1234 app/web.2:  [s] GET    200 199.255.11.2    /charts/summary.json parameters={"venue_id"=>"", "end_date"=>"", "time_range"=>"1 week", "group_method"=>"", "id"=>"summary"} (app:2ms db:298ms) 
May 29 09:23:44 sushi-app-1234 app/web.1:  [s] GET    404 199.255.11.2    /businesses/90000 parameters={"subdomain"=>"business", "id"=>"90000"} ActiveRecord::RecordNotFound Couldn't find Business with 'id'=90000 (app:0ms db:83ms) 
May 29 09:23:44 sushi-app-1234 app/web.1:  ActiveRecord::RecordNotFound (Couldn't find Business with 'id'=90000): 
May 29 09:23:44 sushi-app-1234 app/web.1:    app/controllers/dashboard/businesses_controller.rb:15:in `find_business' 
May 29 09:23:44 sushi-app-1234 app/web.1:  ** [NewRelic][05/29/15 16:23:44 +0000 web.1 (6)] INFO : Reporting to: https://rpm.newrelic.com/accounts/123456/applications/2274532 
May 29 09:23:45 sushi-app-1234 app/web.2:  [s]  
May 29 09:23:45 sushi-app-1234 app/web.2:  ActionController::RoutingError (No route matches [GET] "/assets/active_admin_ex.css"): 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/railties-4.2.1/lib/rails/rack/logger.rb:38:in `call_app' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/railties-4.2.1/lib/rails/rack/logger.rb:20:in `block in call' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.1/lib/active_support/tagged_logging.rb:68:in `block in tagged' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.1/lib/active_support/tagged_logging.rb:26:in `tagged' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.1/lib/active_support/tagged_logging.rb:68:in `tagged' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/railties-4.2.1/lib/rails/rack/logger.rb:20:in `call' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/request_id.rb:21:in `call' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/rack-1.6.1/lib/rack/methodoverride.rb:22:in `call' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/rack-1.6.1/lib/rack/runtime.rb:18:in `call' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.1/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/static.rb:113:in `call' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/rack-1.6.1/lib/rack/sendfile.rb:113:in `call' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/railties-4.2.1/lib/rails/engine.rb:518:in `call' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/railties-4.2.1/lib/rails/application.rb:164:in `call' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/railties-4.2.1/lib/rails/railtie.rb:194:in `public_send' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/railties-4.2.1/lib/rails/railtie.rb:194:in `method_missing' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/rack-1.6.1/lib/rack/deflater.rb:35:in `call' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.11.2.286/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:576:in `process_client' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:670:in `worker_loop' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:525:in `spawn_missing_workers' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:140:in `start' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/bin/unicorn:126:in `<top (required)>' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/bin/unicorn:23:in `load' 
May 29 09:23:45 sushi-app-1234 app/web.2:    vendor/bundle/ruby/2.1.0/bin/unicorn:23:in `<main>' 

I think it is fine to show stack trace in that format.

Does this mean it's working on Heroku? I'd like to close the issue if so.

It will be nice to consider this errors, simply 404 and not show the stacktrace. As for Heroku (the original issue), it works as long as users do not install rails_stdout_loging (against Heroku's suggestion): by doing that, is up to the user to redirect the logs to STDOUT, see example bellow.

I could submit a PR for a new section on the README if you want. But consider the issue closed.

# Gemfile
# gem 'rails_12factor', group: :production
gem 'rails_serve_static_assets', group: :production

# production.rb
config.log_level = :warn
config.logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
config.logger.level = Logger.const_get(config.log_level.to_s.upcase)