Forum: Ruby How to check if the logfile of a Logger instance is closed?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
084b13bebff6514ac50cd171c4e10e51?d=identicon&s=25 ChrisKaelin (Guest)
on 2007-04-17 16:26
(Received via mailing list)
If I do:

l = Logger.new("testlog")
l.close

now if I want to close it again, I get:
IOError: closed stream

So far, I have checked for this error (by rescue clause), to see, if
the logfile is already closed. Is there a more elegant way to check if
the instance (i.e. the logfile stream) is already closed?
1b5341b64f7ce0244366eae17f06c801?d=identicon&s=25 unknown (Guest)
on 2007-04-17 16:49
(Received via mailing list)
On Tue, 17 Apr 2007, ChrisKaelin wrote:

> the instance (i.e. the logfile stream) is already closed?
Logger doesn't provide a method to check this, so what you are doing is
right.

You can look at log4r (http://log4r.sourceforge.net/) for a logger that
supports a closed? method, and which is pretty flexible.

You might also look at my asynchronous logger, Analogger
(http://analogger.swiftcore.org).  It supports a closed? method, as
well.

It also looks like it would be pretty easy to subclass Logger and
LogDevice to create a version that implements closed?.


Kirk Haines
084b13bebff6514ac50cd171c4e10e51?d=identicon&s=25 ChrisKaelin (Guest)
on 2007-04-17 17:25
(Received via mailing list)
khaines@enigo.com wrote:
> > So far, I have checked for this error (by rescue clause), to see, if
> (http://analogger.swiftcore.org).  It supports a closed? method, as
> well.
>
> It also looks like it would be pretty easy to subclass Logger and
> LogDevice to create a version that implements closed?.
>
>
> Kirk Haines
Thanks, I was thinking too of subclassing Logger for that, but the
rescue clause seems to do this work well enough ;-)

Analogger looks great, but for my simple script framework it is a bit
too much. I'll check it, if I do bigger projects in the future...
This topic is locked and can not be replied to.