From 072e166fefb9c787a012afa66688558f4a364d2d Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Sat, 11 Nov 2017 23:38:15 +0100 Subject: [PATCH] print output from info and warnings in one shot, to prevent interleaving when used async (#24530) (cherry picked from commit 1cd62b3b48d494b67eb7a15b031bc2b3379ca97c) --- base/util.jl | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/base/util.jl b/base/util.jl index 66972107def5b..e6a014c43f830 100644 --- a/base/util.jl +++ b/base/util.jl @@ -524,9 +524,11 @@ MY INFO: hello world See also [`logging`](@ref). """ function info(io::IO, msg...; prefix="INFO: ") - io = redirect(io, log_info_to, :info) - print_with_color(info_color(), io, prefix; bold = true) - println_with_color(info_color(), io, chomp(string(msg...))) + buf = IOBuffer() + iob = redirect(IOContext(buf, io), log_info_to, :info) + print_with_color(info_color(), iob, prefix; bold = true) + println_with_color(info_color(), iob, chomp(string(msg...))) + print(io, String(take!(buf))) return end info(msg...; prefix="INFO: ") = info(STDERR, msg..., prefix=prefix) @@ -559,16 +561,18 @@ function warn(io::IO, msg...; (key in have_warned) && return push!(have_warned, key) end - io = redirect(io, log_warn_to, :warn) - print_with_color(warn_color(), io, prefix; bold = true) - print_with_color(warn_color(), io, str) + buf = IOBuffer() + iob = redirect(IOContext(buf, io), log_warn_to, :warn) + print_with_color(warn_color(), iob, prefix; bold = true) + print_with_color(warn_color(), iob, str) if bt !== nothing - show_backtrace(io, bt) + show_backtrace(iob, bt) end if filename !== nothing - print(io, "\nwhile loading $filename, in expression starting on line $lineno") + print(iob, "\nwhile loading $filename, in expression starting on line $lineno") end - println(io) + println(iob) + print(io, String(take!(buf))) return end