El Lunes, 4 de Enero de 2010, Eric Wong escribió:
> Iñaki Baz Castillo <i...@aliax.net> wrote:
> > El Domingo, 3 de Enero de 2010, Eric Wong escribió:
> > >   # 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')
> >
> > Unfortunatelly it doesn'w work very well. First of all Sysloglogger
> > relies on a constant called SYSLOG created in "initialize" method so it's
> > required to add the above methods to SyslogLogger class rather than
> > subclass.
> >
> > Anyhow, the main problem is that by doing "$stderr =
> > SyslogLogger.new('foo')" the std error is not redirected as /proc/PID/fd
> > still shows:
> >
> >   2 -> /dev/pts/2
> 
> Yup, that's expected.  _Assigning_ $stderr does not do a redirect at the
> OS-level, only at th Ruby level (sufficient for env["rack.errors"],
> Kernel#warn).
> 
> > Of course by calling $stderr.puts "error" the above works, but when a
> > real error raised it's is printed in the screen (/dev/pts/2).
> >
> > I strongly think that IO#reopen is required. IO#reopen accepts a string
> > (file path) or other IO, so "converting" SyslogLogger into a IO is
> > required.
> >
> > I'll try to achieve it.
> 
> Yes, you need to do something that'll dup()/dup2() internally like
> IO#reopen to replace fd=2.  But when you have the raw file descriptor,
> you won't get syslog formatting...
> 
> The only way I can think of is to redirect fd=2 to the stdin of a
> separate process to add formatting in...
> 
>   r, w = IO.pipe
>   fork {
>      $stdin.reopen(r)
>      w.close
>      exec('ruby', '-rsyslog', '-ane',
>           'BEGIN{Syslog.open("foo")}; Syslog.warning $_')
>   }
>   r.close
>   $stderr.reopen(w)
> 
> Not pretty...


Thanks. Definitively it seems too much complex so I'll change myidea and will 
use a normal text file for stderr when running daemonized.

Thanks a lot.


-- 
Iñaki Baz Castillo <i...@aliax.net>
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying

Reply via email to