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

  • Thread starter Iñaki Baz Castillo
  • Start date
I

Iñaki Baz Castillo

Hi, is it possible to redirect $stderr to any available logger instance (as=
=20
Logger, SyslogLogger, Logging)?

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

Thanks for any comment.

=2D-=20
I=C3=B1aki Baz Castillo <[email protected]>
 
T

Tim Pease

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

$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 =3D logger.get_logger_file_descriptor
$stderr.reopen new_fd


Blessings,
TwP=
 
I

Iñaki Baz Castillo

El S=E1bado, 2 de Enero de 2010, Tim Pease escribi=F3:
=20
$stderr is a file descriptor. You can reopen the descriptor to any other
valid descriptor: file, socket, pipe, unix socket, etc.
=20
For any of the loggers you mentioned above, get a hold of the internal
descriptor the logger is using and then ....
=20
new_fd =3D logger.get_logger_file_descriptor
$stderr.reopen new_fd

Thanks. The problem is that Syslog is a daemon rather than a file descripto=
r.=20
This is: Syslog is a daemon which receives messages from syslog clients and=
=20
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 =3D MySyslogLogger.new('foo')



=2D-=20
I=F1aki Baz Castillo <[email protected]>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top