JuliaIO/Suppressor.jl

Logging into `stderr` is not captured

Closed this issue · 0 comments

Drvi commented

e.g.:

with_logger(ConsoleLogger(stderr)) do;
    out = @capture_err begin
        @error "@error"
    end
end
#┌ Error: @error
#└ @ Main REPL[12]:3
# ""

But when I point my logger at a closed IOBuffer, the problem goes a away:

julia> io = IOBuffer()
IOBuffer(data=UInt8[...], readable=true, writable=true, seekable=true, append=false, size=0, maxsize=Inf, ptr=1, mark=-1)

julia> close(io)

julia> with_logger(ConsoleLogger(io)) do;
           out = @capture_err begin
               @error "@error"
           end
       end
"┌ Error: @error\n└ @ Main REPL[16]:3\n"

IIUC, when the logger tries to print to a closed IO, it will print to whatever the current stderr is to avoid losing logs. with_logger sets the new logstate on to the current_task(), so perhaps that is not picked up properly here?