Sean O'Halpin
7/28/2006 2:18:00 PM
On 7/28/06, Pavel Smerk <smerk@fi.muni.cz> wrote:
> Hello,
>
> how can I catch all output going to $stderr (e.g. to send some warning
> emails time to time in case of daemon etc.)?
>
> Thanks,
>
> P.
>
>
Something like this?
ioproxy = STDERR.dup
def ioproxy.write(*args, &block)
p args
#STDERR.write(*args, &block) # if you want to pass it on to real STDERR
end
$stderr = ioproxy
puts "hello"
$stderr.puts "error!"
puts "world"
warn "oops!"
__END__
hello
["error!"]
["\n"]
world
["oops!"]
["\n"]
The newlines are because puts prints its args + newline. You could
easily filter that in the write method.
Regards,
Sean