Skip to content

Commit

Permalink
More cautious legacy_color conversion in Logging
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tecosaur committed Feb 11, 2024
1 parent af90dac commit 9bb4068
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion stdlib/Logging/src/ConsoleLogger.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9bb4068

Please sign in to comment.