Skip to content

Commit db0a882

Browse files
KristofferCaviatesk
KristofferC
authored andcommitted
Revert "Use StyledStrings for Logging (#51829)"
This reverts commit 250916f.
1 parent 597c807 commit db0a882

File tree

7 files changed

+28
-37
lines changed

7 files changed

+28
-37
lines changed

doc/Manifest.toml

-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ uuid = "94ce4f54-9a6c-5748-9c1c-f9c7231a4531"
144144
version = "1.17.0+0"
145145

146146
[[deps.Logging]]
147-
deps = ["StyledStrings"]
148147
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
149148
version = "1.11.0"
150149

stdlib/Logging/Project.toml

-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ name = "Logging"
22
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
33
version = "1.11.0"
44

5-
[deps]
6-
StyledStrings = "f489334b-da3d-4c2e-b8f0-e476e12c162b"
7-
85
[extras]
96
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
107

stdlib/Logging/src/ConsoleLogger.jl

+15-18
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ Log levels less than `min_level` are filtered out.
1212
Message formatting can be controlled by setting keyword arguments:
1313
1414
* `meta_formatter` is a function which takes the log event metadata
15-
`(level, _module, group, id, file, line)` and returns a face name (used in
16-
the constructed [`AnnotatedString`](@ref Base.AnnotatedString)), prefix and
17-
suffix for the log message. The default is to prefix with the log level and
18-
a suffix containing the module, file and line location.
15+
`(level, _module, group, id, file, line)` and returns a color (as would be
16+
passed to printstyled), prefix and suffix for the log message. The
17+
default is to prefix with the log level and a suffix containing the module,
18+
file and line location.
1919
* `show_limited` limits the printing of large data structures to something
2020
which can fit on the screen by setting the `:limit` `IOContext` key during
2121
formatting.
@@ -58,10 +58,10 @@ end
5858
showvalue(io, ex::Exception) = showerror(io, ex)
5959

6060
function default_logcolor(level::LogLevel)
61-
level < Info ? :log_debug :
62-
level < Warn ? :log_info :
63-
level < Error ? :log_warn :
64-
:log_error
61+
level < Info ? Base.debug_color() :
62+
level < Warn ? Base.info_color() :
63+
level < Error ? Base.warn_color() :
64+
Base.error_color()
6565
end
6666

6767
function default_metafmt(level::LogLevel, _module, group, id, file, line)
@@ -103,8 +103,6 @@ function termlength(str)
103103
return N
104104
end
105105

106-
termlength(str::Base.AnnotatedString) = textwidth(str)
107-
108106
function handle_message(logger::ConsoleLogger, level::LogLevel, message, _module, group, id,
109107
filepath, line; kwargs...)
110108
@nospecialize
@@ -156,7 +154,6 @@ function handle_message(logger::ConsoleLogger, level::LogLevel, message, _module
156154
# Format lines as text with appropriate indentation and with a box
157155
# decoration on the left.
158156
color, prefix, suffix = logger.meta_formatter(level, _module, group, id, filepath, line)::Tuple{Union{Symbol,Int},String,String}
159-
color = StyledStrings.Face(foreground=StyledStrings.Legacy.legacy_color(color))
160157
minsuffixpad = 2
161158
buf = IOBuffer()
162159
iob = IOContext(buf, stream)
@@ -170,19 +167,19 @@ function handle_message(logger::ConsoleLogger, level::LogLevel, message, _module
170167
nonpadwidth = 2 + length(suffix)
171168
end
172169
for (i, (indent, msg)) in enumerate(msglines)
173-
boxstr = length(msglines) == 1 ? "[" :
174-
i == 1 ? "" :
175-
i < length(msglines) ? "" :
176-
""
177-
print(iob, styled"{$color,bold:$boxstr} ")
170+
boxstr = length(msglines) == 1 ? "[ " :
171+
i == 1 ? " " :
172+
i < length(msglines) ? " " :
173+
" "
174+
printstyled(iob, boxstr, bold=true, color=color)
178175
if i == 1 && !isempty(prefix)
179-
print(iob, styled"{$color,bold:$prefix} ")
176+
printstyled(iob, prefix, " ", bold=true, color=color)
180177
end
181178
print(iob, " "^indent, msg)
182179
if i == length(msglines) && !isempty(suffix)
183180
npad = max(0, justify_width - nonpadwidth) + minsuffixpad
184181
print(iob, " "^npad)
185-
print(iob, styled"{shadow:$suffix}")
182+
printstyled(iob, suffix, color=:light_black)
186183
end
187184
println(iob)
188185
end

stdlib/Logging/src/Logging.jl

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ and available by default.
88
"""
99
module Logging
1010

11-
using StyledStrings
12-
1311
# Import the CoreLogging implementation into Logging as new const bindings.
1412
# Doing it this way (rather than with import) makes these symbols accessible to
1513
# tab completion.

stdlib/Logging/test/runtests.jl

+12-12
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,24 @@ end
6363

6464
@testset "Default metadata formatting" begin
6565
@test Logging.default_metafmt(Logging.Debug, Base, :g, :i, expanduser("~/somefile.jl"), 42) ==
66-
(:log_debug, "Debug:", "@ Base ~/somefile.jl:42")
66+
(:blue, "Debug:", "@ Base ~/somefile.jl:42")
6767
@test Logging.default_metafmt(Logging.Info, Main, :g, :i, "a.jl", 1) ==
68-
(:log_info, "Info:", "")
68+
(:cyan, "Info:", "")
6969
@test Logging.default_metafmt(Logging.Warn, Main, :g, :i, "b.jl", 2) ==
70-
(:log_warn, "Warning:", "@ Main b.jl:2")
70+
(:yellow, "Warning:", "@ Main b.jl:2")
7171
@test Logging.default_metafmt(Logging.Error, Main, :g, :i, "", 0) ==
72-
(:log_error, "Error:", "@ Main :0")
72+
(:light_red, "Error:", "@ Main :0")
7373
# formatting of nothing
7474
@test Logging.default_metafmt(Logging.Warn, nothing, :g, :i, "b.jl", 2) ==
75-
(:log_warn, "Warning:", "@ b.jl:2")
75+
(:yellow, "Warning:", "@ b.jl:2")
7676
@test Logging.default_metafmt(Logging.Warn, Main, :g, :i, nothing, 2) ==
77-
(:log_warn, "Warning:", "@ Main")
77+
(:yellow, "Warning:", "@ Main")
7878
@test Logging.default_metafmt(Logging.Warn, Main, :g, :i, "b.jl", nothing) ==
79-
(:log_warn, "Warning:", "@ Main b.jl")
79+
(:yellow, "Warning:", "@ Main b.jl")
8080
@test Logging.default_metafmt(Logging.Warn, nothing, :g, :i, nothing, 2) ==
81-
(:log_warn, "Warning:", "")
81+
(:yellow, "Warning:", "")
8282
@test Logging.default_metafmt(Logging.Warn, Main, :g, :i, "b.jl", 2:5) ==
83-
(:log_warn, "Warning:", "@ Main b.jl:2-5")
83+
(:yellow, "Warning:", "@ Main b.jl:2-5")
8484
end
8585

8686
function dummy_metafmt(level, _module, group, id, file, line)
@@ -265,9 +265,9 @@ end
265265
# Basic colorization test
266266
@test genmsg("line1\nline2", color=true) ==
267267
"""
268-
\e[36m\e[1m┌\e[39m\e[22m \e[36m\e[1mPREFIX\e[39m\e[22m line1
269-
\e[36m\e[1m│\e[39m\e[22m line2
270-
\e[36m\e[1m└\e[39m\e[22m \e[90mSUFFIX\e[39m
268+
\e[36m\e[1m┌ \e[22m\e[39m\e[36m\e[1mPREFIX \e[22m\e[39mline1
269+
\e[36m\e[1m│ \e[22m\e[39mline2
270+
\e[36m\e[1m└ \e[22m\e[39m\e[90mSUFFIX\e[39m
271271
"""
272272

273273
end

stdlib/Manifest.toml

-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
130130
version = "1.11.0"
131131

132132
[[deps.Logging]]
133-
deps = ["StyledStrings"]
134133
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
135134
version = "1.11.0"
136135

test/precompile.jl

+1
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ precompile_test_harness(false) do dir
447447
Dict(Base.PkgId(Base.root_module(Base, :Markdown)) => Base.module_build_id(Base.root_module(Base, :Markdown))),
448448
Dict(Base.PkgId(Base.root_module(Base, :JuliaSyntaxHighlighting)) => Base.module_build_id(Base.root_module(Base, :JuliaSyntaxHighlighting))),
449449
Dict(Base.PkgId(Base.root_module(Base, :StyledStrings)) => Base.module_build_id(Base.root_module(Base, :StyledStrings))),
450+
450451
# and their dependencies
451452
Dict(Base.PkgId(Base.root_module(Base, :Base64)) => Base.module_build_id(Base.root_module(Base, :Base64))),
452453
)

0 commit comments

Comments
 (0)