diff --git a/base/client.jl b/base/client.jl index 2aaf9a52544d6..f28a1bab86de4 100644 --- a/base/client.jl +++ b/base/client.jl @@ -69,6 +69,7 @@ have_color = false default_color_warn = :yellow default_color_error = :light_red default_color_info = :cyan +default_color_debug = :blue default_color_input = :normal default_color_answer = :normal color_normal = text_colors[:normal] @@ -83,6 +84,7 @@ end error_color() = repl_color("JULIA_ERROR_COLOR", default_color_error) warn_color() = repl_color("JULIA_WARN_COLOR" , default_color_warn) info_color() = repl_color("JULIA_INFO_COLOR" , default_color_info) +debug_color() = repl_color("JULIA_DEBUG_COLOR" , default_color_debug) input_color() = text_colors[repl_color("JULIA_INPUT_COLOR", default_color_input)] answer_color() = text_colors[repl_color("JULIA_ANSWER_COLOR", default_color_answer)] diff --git a/base/logging.jl b/base/logging.jl index 8085c195642a6..2b9830fc2f978 100644 --- a/base/logging.jl +++ b/base/logging.jl @@ -343,8 +343,9 @@ 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" + msg *= join(" " .* split(sprint(showerror, err), "\n"), "\n") + handle_message(logger, Error, msg, _module, group, id, filepath, line) catch err2 try # Give up and write to STDERR, in three independent calls to @@ -483,23 +484,30 @@ function handle_message(logger::SimpleLogger, level, message, _module, group, id logger.message_limits[id] = remaining - 1 remaining > 0 || return end - levelstr = string(level) - color = level < Info ? :blue : - level < Warn ? :cyan : - level < Error ? :yellow : :red + levelstr, color = level < Info ? ("Debug", Base.debug_color()) : + level < Warn ? ("Info", Base.info_color()) : + level < Error ? ("Warning", Base.warn_color()) : + ("Error", Base.error_color()) buf = IOBuffer() iob = IOContext(buf, logger.stream) - print_with_color(color, iob, first(levelstr), "- ", bold=true) - msglines = split(string(message), '\n') - for i in 1:length(msglines)-1 - println(iob, msglines[i]) - print_with_color(color, iob, "| ", bold=true) - end - println(iob, msglines[end], " -", levelstr, ":", _module, ":", basename(filepath), ":", line) - for (key,val) in pairs(kwargs) - print_with_color(color, iob, "| ", bold=true) - println(iob, key, " = ", val) + msglines = split(chomp(string(message)), '\n') + if length(msglines) + length(kwargs) == 1 + print_with_color(color, iob, "[ ", levelstr, ": ", bold=true) + print(iob, msglines[1], " ") + else + print_with_color(color, iob, "┌ ", levelstr, ": ", bold=true) + println(iob, msglines[1]) + for i in 2:length(msglines) + print_with_color(color, iob, "│ ", bold=true) + println(iob, msglines[i]) + end + for (key,val) in pairs(kwargs) + print_with_color(color, iob, "│ ", bold=true) + println(iob, " ", key, " = ", val) + end + print_with_color(color, iob, "└ ", bold=true) end + print_with_color(:light_black, iob, "@ ", _module, " ", basename(filepath), ":", line, "\n") write(logger.stream, take!(buf)) nothing end diff --git a/base/replutil.jl b/base/replutil.jl index 8ad88cef24d0e..d589111053edc 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 diff --git a/test/logging.jl b/test/logging.jl index 5b5610d87a80c..b726ac8e3f100 100644 --- a/test/logging.jl +++ b/test/logging.jl @@ -249,22 +249,24 @@ end # Simple @test genmsg(Info, "msg", Main, "some/path.jl", 101) == """ - I- msg -Info:Main:path.jl:101 + [ Info: msg @ Main path.jl:101 """ # Multiline message @test genmsg(Warn, "line1\nline2", Main, "some/path.jl", 101) == """ - W- line1 - | line2 -Warn:Main:path.jl:101 + ┌ Warning: line1 + │ line2 + └ @ Main path.jl:101 """ # Keywords @test genmsg(Error, "msg", Base, "other.jl", 101, a=1, b="asdf") == """ - E- msg -Error:Base:other.jl:101 - | a = 1 - | b = asdf + ┌ Error: msg + │ a = 1 + │ b = asdf + └ @ Base other.jl:101 """ end