Raised exceptions are not logged when USR2

Eric Wong normalperson at yhbt.net
Sat Jan 2 19:04:01 EST 2010


Iñaki Baz Castillo <ibc at aliax.net> wrote:
> El Sábado, 2 de Enero de 2010, Iñaki Baz Castillo escribió:
> > A simpler approach would be removing this line at the end of launcher.rb:
> > 
> >   Unicorn::Configurator::DEFAULTS[:stderr_path] = "/dev/null"
> > 
> > With this, errors would be displayed in stderr. Of course for workers
> >  stderr should be reopened to point to /dev/null, but IMHO not for master
> >  process.
> > 
> > Perhaps errors preventing the master process to start should be displayed
> >  to stderr instead of to the logger (as it could be not set yet).
> 
> And the other already available workaround is setting the "stderr_path".
> Unfortunatelly $stderr.reopen requires a file as parameter so is not possible 
> to use Syslog or any other logger, is it?

Hi Iñaki,

Unfortunately, the stock Syslog module isn't compatible with the Ruby
Logger implementation.  Try grabbing the "SyslogLogger" gem and using
that instead.  I haven't had any experience with SyslogLogger, but a
cursory look says it's OK.

I would always keep stderr_path set somewhere in your config file since
by default "rack.errors" points to it, and it's the default place for
Kernel#warn to output to.

If you really want to, you may be able to subclass SyslogLogger and give
it IO-like methods (write/puts/flush) are require for Rack::Lint
compatibility and then set $stderr:

  # Totally untested, stick this in your Unicorn config file and let
  # us know if it works or blows up badly:

  require 'syslog_logger'

  class MySyslogLogger < SyslogLogger
    alias puts error
    alias write error
    def flush; self; end
  end

  $stderr = MySyslogLogger.new('foo')

> BTW, how to reset the $stderr so it points again to the default one (the 
> terminal)?

You would've had to dup stderr in the config file and keep it referenced
before it got redirected.  But a daemonized process shouldn't be holding
onto terminals...

-- 
Eric Wong


More information about the mongrel-unicorn mailing list