Skip to content

Commit

Permalink
print output from info and warnings in one shot, to prevent interleav…
Browse files Browse the repository at this point in the history
…ing when used async (#24530)

(cherry picked from commit 1cd62b3)
  • Loading branch information
KristofferC authored and ararslan committed Nov 11, 2017
1 parent 3259ae2 commit 072e166
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions base/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 072e166

Please sign in to comment.