Have Unicorn Log to $stdout

A strange quirk of Unicorn is that by default it will write all its logging output to $stderr. Even a relatively harmless operation like a restart will result in noise written to your system error log:

executing ["/home/core/.bundle/gems/ruby/1.8/bin/unicorn_rails", "-c", "config/normalized_unicorn.rb"] (in /home/core)
forked child re-executing...
I, [2012-10-17T09:00:35.029145 #12322]  INFO -- : inherited addr=/tmp/core.sock fd=4
I, [2012-10-17T09:00:35.029885 #12322]  INFO -- : Refreshing Gem list
reaped #<Process::Status: pid=2784,exited(0)> worker=1
reaped #<Process::Status: pid=2785,exited(0)> worker=2
reaped #<Process::Status: pid=2783,exited(0)> worker=0
master complete
master process ready
worker=1 ready
worker=2 ready
worker=0 ready

Simply redefining Unicorn’s logger to one pointing to $stdout will fix the problem:

# by default, Unicorn will log to $stderr; go to $stdout instead
logger Logger.new($stdout)

Posted on October 21, 2012 from San Francisco

About

My name is Brandur. I'm a polyglot software engineer and part-time designer working at Heroku in San Francisco, California. I'm a Canadian expat. My name is Icelandic. Drop me a line at brandur@mutelight.org.

Aside from technology, I'm interested in energy and how it relates to our society, travel, longboarding, muay thai, symphonic metal, and the guitar.

If you liked this article, consider finding me on Twitter.