Heroku logging not working

痞子三分冷 提交于 2019-12-17 22:42:10

问题


I've got a rails 3.1 app deployed on Heroku Cedar. I'm having a problem with the logging. The default rails logs are working just fine, but when I do something like:

logger.info "log this message"

In my controller, Heroku doesn't log anything. When I deploy my app I see the heroku message "Injecting rails_log_stdout" so I think calling the logger should work just fine. Puts statements end up in my logs. I've also tried other log levels like logger.error. Nothing works. Has anyone else seen this?


回答1:


I was just having the same issue, solved by using the technique here:

https://github.com/ryanb/cancan/issues/511

Basically, you need to specify the logger outputs to STDOUT, some gems interfere with the logger and seem to hijack the functionality (cancan in my case).

For the click lazy, just put this in environments/production.rb

config.logger = Logger.new(STDOUT) 
config.log_level = :info



回答2:


MBHNYC's answer works great, but it makes it difficult to change the log level in different environments without changing the code. You can use this code in your environments/production.rb to honor an environment variable as well as have a reasonable default:

# https://github.com/ryanb/cancan/issues/511
config.logger = Logger.new(STDOUT)
config.logger.level = Logger.const_get((ENV["LOG_LEVEL"] || "INFO").upcase)

Use this command to set a different log level:

heroku config:set LOG_LEVEL=error



回答3:


As of the moment, it looks like heroku injects these two plugins when building the slug:

rails_log_stdout - https://github.com/ddollar/rails_log_stdout

rails3_server_static_assets - https://github.com/pedro/rails3_serve_static_assets

Anything sent to the pre-existing Rails logger will be discarded and will not be visible in logs. Just adding this for completeness for anyone else who ends up here.




回答4:


The problem, as @MBHNYC correctly addressed, is that your logs are not going to STDOUT.

Instead of configuring manually all that stuff, Heroku provides a gem that does this all for you.

Just put

gem 'rails_12factor', group: :production

in your Gemfile, bundle, and that's it!

NOTE: This works both for Rails 3 and 4.

Source: Rails 4 on Heroku



来源:https://stackoverflow.com/questions/8098429/heroku-logging-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!