From 9d2bc2cbd9a57950e53e527721c5f5faa2723b2d Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Sun, 24 Dec 2017 13:01:09 +0100 Subject: [PATCH] some logging things - use user customizable colors - nice box drawing chars - print line info after key value pairs - always put the line info on its own line for multiline messages - indent key-value pair - print line info in grey --- base/client.jl | 2 ++ base/logging.jl | 35 +++++++++++++++++++++-------------- test/logging.jl | 14 ++++++++------ 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/base/client.jl b/base/client.jl index c2b2a439d57b0..7ac81976e0485 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..9c7559737c673 100644 --- a/base/logging.jl +++ b/base/logging.jl @@ -483,23 +483,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/test/logging.jl b/test/logging.jl index cee9bb7982348..5a11a97d0357b 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