From 9bb4068cd27333fe7103a19518fc240244009ef9 Mon Sep 17 00:00:00 2001 From: TEC Date: Sun, 11 Feb 2024 17:53:12 +0800 Subject: [PATCH] More cautious legacy_color conversion in Logging While the original line color = StyledStrings.Face(foreground=StyledStrings.Legacy.legacy_color(color)) does a perfectly adequate job of mapping old color names to `SimpleColor`s, it neglects the newer capability of using named `Faces` with logging. It is better to first check that the value of `color` can indeed be recognised as a `legacy_color`-compatible named color, before using it as the foreground value. --- stdlib/Logging/src/ConsoleLogger.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stdlib/Logging/src/ConsoleLogger.jl b/stdlib/Logging/src/ConsoleLogger.jl index 0922e9fcc66c9b..e498e51f0ac4d9 100644 --- a/stdlib/Logging/src/ConsoleLogger.jl +++ b/stdlib/Logging/src/ConsoleLogger.jl @@ -148,7 +148,9 @@ function handle_message(logger::ConsoleLogger, level::LogLevel, message, _module # Format lines as text with appropriate indentation and with a box # decoration on the left. color, prefix, suffix = logger.meta_formatter(level, _module, group, id, filepath, line)::Tuple{Union{Symbol,Int},String,String} - color = StyledStrings.Face(foreground=StyledStrings.Legacy.legacy_color(color)) + if (lcolor = StyledStrings.Legacy.legacy_color(color)) |> !isnothing + color = StyledStrings.Face(foreground=lcolor) + end minsuffixpad = 2 buf = IOBuffer() iob = IOContext(buf, stream)