Skip to content

Commit 8742d3c

Browse files
authored
Move ConsoleLogging.jl into Base (#54428)
Fixes #51493, fixes #52075
2 parents 5006312 + 3638c84 commit 8742d3c

File tree

10 files changed

+37
-53
lines changed

10 files changed

+37
-53
lines changed

base/Base.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,13 +402,13 @@ include("weakkeydict.jl")
402402
include("scopedvalues.jl")
403403
using .ScopedValues
404404

405-
# Logging
406-
include("logging.jl")
407-
using .CoreLogging
408-
409405
# metaprogramming
410406
include("meta.jl")
411407

408+
# Logging
409+
include("logging/logging.jl")
410+
using .CoreLogging
411+
412412
include("env.jl")
413413

414414
# functions defined in Random
@@ -634,6 +634,8 @@ function __init__()
634634
if get_bool_env("JULIA_USE_FLISP_PARSER", false) === false
635635
JuliaSyntax.enable_in_core!()
636636
end
637+
638+
CoreLogging.global_logger(CoreLogging.ConsoleLogger())
637639
nothing
638640
end
639641

stdlib/Logging/src/ConsoleLogger.jl renamed to base/logging/ConsoleLogger.jl

Lines changed: 15 additions & 21 deletions
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,10 +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-
lcolor = StyledStrings.Legacy.legacy_color(color)
160-
if !isnothing(lcolor)
161-
color = StyledStrings.Face(foreground=lcolor)
162-
end
163157
minsuffixpad = 2
164158
buf = IOBuffer()
165159
iob = IOContext(buf, stream)
@@ -173,19 +167,19 @@ function handle_message(logger::ConsoleLogger, level::LogLevel, message, _module
173167
nonpadwidth = 2 + length(suffix)
174168
end
175169
for (i, (indent, msg)) in enumerate(msglines)
176-
boxstr = length(msglines) == 1 ? "[" :
177-
i == 1 ? "" :
178-
i < length(msglines) ? "" :
179-
""
180-
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)
181175
if i == 1 && !isempty(prefix)
182-
print(iob, styled"{$color,bold:$prefix} ")
176+
printstyled(iob, prefix, " ", bold=true, color=color)
183177
end
184178
print(iob, " "^indent, msg)
185179
if i == length(msglines) && !isempty(suffix)
186180
npad = max(0, justify_width - nonpadwidth) + minsuffixpad
187181
print(iob, " "^npad)
188-
print(iob, styled"{shadow:$suffix}")
182+
printstyled(iob, suffix, color=:light_black)
189183
end
190184
println(iob)
191185
end

base/logging.jl renamed to base/logging/logging.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,4 +700,6 @@ end
700700

701701
_global_logstate = LogState(SimpleLogger())
702702

703+
include("logging/ConsoleLogger.jl")
704+
703705
end # CoreLogging

base/meta.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ Convenience functions for metaprogramming.
55
"""
66
module Meta
77

8-
using ..CoreLogging
9-
108
export quot,
119
isexpr,
1210
isidentifier,

doc/Manifest.toml

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 3 deletions
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/Logging.jl

Lines changed: 1 addition & 9 deletions
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.
@@ -70,7 +68,7 @@ Alias for [`LogLevel(1_000_001)`](@ref LogLevel).
7068
const AboveMaxLevel = Base.CoreLogging.AboveMaxLevel
7169

7270
using Base.CoreLogging:
73-
closed_stream
71+
closed_stream, ConsoleLogger, default_metafmt
7472

7573
export
7674
AbstractLogger,
@@ -94,8 +92,6 @@ export
9492
Error,
9593
AboveMaxLevel
9694

97-
include("ConsoleLogger.jl")
98-
9995
# The following are also part of the public API, but not exported:
10096
#
10197
# 1. Log levels:
@@ -104,8 +100,4 @@ include("ConsoleLogger.jl")
104100
# 2. AbstractLogger message related functions:
105101
# handle_message, shouldlog, min_enabled_level, catch_exceptions,
106102

107-
function __init__()
108-
global_logger(ConsoleLogger())
109-
end
110-
111103
end

stdlib/Logging/test/runtests.jl

Lines changed: 12 additions & 12 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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)