Issues with println buffering output when redirecting stdout to a txt file

Using a wrapper type would be a clean solution. Eg (just a starting point, modify/extend as needed):

struct FlushingIO{T}
    io::T
end

function Base.print(io::FlushingIO, args...)
    print(io.io, args...)
    flush(io.io)
end

out = FlushingIO(stdout)
my_function(out, ...)
1 Like