Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku logging not working

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?

like image 623
joshuacronemeyer Avatar asked Nov 11 '11 18:11

joshuacronemeyer


People also ask

How do I get heroku logs?

You can view logs with the Heroku CLI, the dashboard, your logging add-on, or in your log drain. You can't view logs for apps in Shield spaces with Private Space Logging enabled. Retrieve logs from your log drain instead.

Why my heroku app is not working?

There are some errors which only occur when the app is rebooting so you will need to restart the app to see these log messages appear. For most apps, we also recommend enabling one of the free logging addons from https://elements.heroku.com/addons#logging to make sure that your historical log data is being saved.

What does heroku logs -- tail mean?

Resolution. Apps that exceed a threshold of log output over a period of time can have their Heroku-provided log buffer disabled, meaning that only heroku logs --tail (live log tailing) will display logs. Note that this does not affect external log drains in any way.

How do I see heroku errors?

Simply use heroku logs to display the last 100 lines of your logs. Heroku only saves the last 1500 lines of logs, which you can access using heroku logs -n 1500 . If you want more logging, check out Heroku add-ons like Logentries or Papertrail.


2 Answers

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
like image 133
Phil Calvin Avatar answered Oct 12 '22 14:10

Phil Calvin


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
like image 38
MBHNYC Avatar answered Oct 12 '22 12:10

MBHNYC