Logging from Heroku apps using unicorn


18 Feb, 2012 09:43 PM UTC


This is now documented on Unicorn, which supercedes this forum thread. Head over there.

Original post (archived)

Documenting this as a forum thread since we received a question about it.

Important: Very few Heroku users will encounter this problem. If you haven't installed unicorn manually, ignore this.


As of this post, a Rails 3.1.3 app using Unicorn 4.1.1 on Heroku (cedar) outputs few or no app logs. Read more here or here.

When a Rails app is deployed, Heroku injects rails_log_stdout, which redefines Rails' Logger so all output goes to STDOUT. This doesn't work as expected with unicorn and only rack output is logged.


To output app logs, edit config/environments/production.rb or the environment configuration for your Heroku environment.

In the MyApp::Cofiguration.configure .. end block, add these 2 lines:

config.logger = Logger.new(STDOUT)
config.logger.level = Logger.const_get(ENV['LOG_LEVEL'] ? ENV['LOG_LEVEL'].upcase : 'INFO')

These create a new Logger class which outputs to STDOUT, then sets its log level.

Note: the second line should set config.logger.level, not config.log_level. Comment out any existing assignments of config.log_level; they won't take effect.

Change INFO to the log level you want to run by default. That's typically INFO in production, though DEBUG (more verbose) and WARN (less verbose) are common.

To change the log level of your running Heroku app, run:

heroku config:add LOG_LEVEL="debug"

.. where debug is the desired log level. Your app will restart immediately at the new log level.

Optional: Disable rails_log_stdout

Optionally, you can tell Heroku not to inject rails_log_stdout since it's no longer needed.

To do so, create an empty vendor/plugins/rails_log_stdout/ directory containing a placeholder file and commit it to your git repo:

mkdir -p vendor/plugins/rails_log_stdout
touch vendor/plugins/rails_log_stdout/keep_me
git add vendor/plugins/rails_log_stdout/keep_me
git commit -m "Placeholder file to disable rails_log_stdout" vendor/plugins/rails_log_stdout/keep_me
  1. 1 Posted by Chap Ambrose on 18 Feb, 2012 09:49 PM UTC

    you rule, in the process of upgrading to rails 3.2.1, i wonder if it has
    the same issues

  2. Support Staff 2 Posted by Troy on 13 Apr, 2013 09:28 PM UTC


    This is now documented on Unicorn. Head over there. It supercedes this forum thread.

  3. This discussion is closed. Please email support@papertrailapp.com to continue troubleshooting this or a related problem.