Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is it possible to redirect $stderr to a Logger isntance?

0 views
Skip to first unread message

Iñaki Baz Castillo

unread,
Jan 2, 2010, 4:37:31 PM1/2/10
to
Hi, is it possible to redirect $stderr to any available logger instance (as
Logger, SyslogLogger, Logging)?

I think it cannot be done, since current Loggers can log to $stderr so we
would get some kind of "loop" XD

Thanks for any comment.

--
Iñaki Baz Castillo <i...@aliax.net>

Tim Pease

unread,
Jan 2, 2010, 4:52:27 PM1/2/10
to

On Jan 2, 2010, at 2:37 PM, Iñaki Baz Castillo wrote:

> Hi, is it possible to redirect $stderr to any available logger instance (as
> Logger, SyslogLogger, Logging)?
>
> I think it cannot be done, since current Loggers can log to $stderr so we
> would get some kind of "loop" XD
>

$stderr is a file descriptor. You can reopen the descriptor to any other valid descriptor: file, socket, pipe, unix socket, etc.

For any of the loggers you mentioned above, get a hold of the internal descriptor the logger is using and then ....

new_fd = logger.get_logger_file_descriptor
$stderr.reopen new_fd


Blessings,
TwP

Iñaki Baz Castillo

unread,
Jan 4, 2010, 4:52:42 AM1/4/10
to

Thanks. The problem is that Syslog is a daemon rather than a file descriptor.
This is: Syslog is a daemon which receives messages from syslog clients and
log them to files or databases.

However I was able to use Syslog as $stderr as follows (thanks to Eric):


require 'syslog_logger' # Logger/Syslog converter

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

$stderr = MySyslogLogger.new('foo')

0 new messages