diff --git a/base/logging.jl b/base/logging.jl index eae786f5b76a20..28f6960ffea0fb 100644 --- a/base/logging.jl +++ b/base/logging.jl @@ -1,6 +1,7 @@ module CoreLogging import Base: isless, +, -, convert, show +using Base: info_color, warn_color, error_color export AbstractLogger, @@ -341,8 +342,10 @@ end # Try really hard to get the message to the logger, with # progressively less information. try - msg = "Exception while generating log record in module $_module at $filepath:$line" - handle_message(logger, Error, msg, _module, group, id, filepath, line; exception=err) + msg = "Exception while generating log record:\n" + str = join(" " .* split(sprint(showerror, err), "\n"), "\n") + msg *= str + handle_message(logger, Error, msg, _module, group, id, filepath, line) catch err2 try # Give up and write to STDERR, in three independent calls to @@ -482,19 +485,27 @@ function handle_message(logger::SimpleLogger, level, message, _module, group, id end levelstr = string(level) color = level < Info ? :blue : - level < Warn ? :cyan : - level < Error ? :yellow : :red + level < Warn ? info_color() : + level < Error ? warn_color() : error_color() buf = IOBuffer() - print_with_color(color, buf, first(levelstr), "- ", bold=true) - msglines = split(string(message), '\n') - for i in 1:length(msglines)-1 - println(buf, msglines[i]) - print_with_color(color, buf, "| ", bold=true) - end - println(buf, msglines[end], " -", levelstr, ":", _module, ":", basename(filepath), ":", line) - for (key,val) in pairs(kwargs) - print_with_color(color, buf, "| ", bold=true) - println(buf, key, " = ", val) + msglines = split(chomp(string(message)), '\n') + if length(msglines) + length(kwargs) == 1 + print_with_color(color, buf, first(levelstr), ": ", bold=true) + # print_with_color(color, buf, "- ") + println(buf, msglines[1], " - ", _module, ":", basename(filepath), ":", line) + else + print_with_color(color, buf, first(levelstr), "┌ ", bold=true) + println(buf, msglines[1]) + for i in 2:length(msglines) + print_with_color(color, buf, " │ ", bold=true) + println(buf, msglines[i]) + end + for (key,val) in pairs(kwargs) + print_with_color(color, buf, " │ ", bold=true) + println(buf, key, " = ", val) + end + print_with_color(color, buf, " └ ", bold=true) + println(buf, _module, ":", basename(filepath), ":", line) end write(logger.stream, take!(buf)) nothing diff --git a/base/replutil.jl b/base/replutil.jl index ac07d984ce1b0b..b477a83814665b 100644 --- a/base/replutil.jl +++ b/base/replutil.jl @@ -267,6 +267,7 @@ function showerror(io::IO, ex::DomainError, bt; backtrace=true) backtrace && show_backtrace(io, bt) nothing end +showerror(io::IO, ex::DomainError) = showerror(io, ex, []) function showerror(io::IO, ex::SystemError) if ex.extrainfo === nothing