From 4b4c4f9885198a31452005ff17512d663e4162f6 Mon Sep 17 00:00:00 2001 From: KristofferC Date: Fri, 10 May 2024 11:47:31 +0200 Subject: [PATCH 1/3] Revert "More cautious legacy_color conversion in Logging (#53280)" This reverts commit 61c3521613767b2af21dfa5cc5a7b8195c5bdcaf. --- stdlib/Logging/src/ConsoleLogger.jl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/stdlib/Logging/src/ConsoleLogger.jl b/stdlib/Logging/src/ConsoleLogger.jl index 08e4a8c6b2efe..2da16a3e34b70 100644 --- a/stdlib/Logging/src/ConsoleLogger.jl +++ b/stdlib/Logging/src/ConsoleLogger.jl @@ -156,10 +156,7 @@ 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} - lcolor = StyledStrings.Legacy.legacy_color(color) - if !isnothing(lcolor) - color = StyledStrings.Face(foreground=lcolor) - end + color = StyledStrings.Face(foreground=StyledStrings.Legacy.legacy_color(color)) minsuffixpad = 2 buf = IOBuffer() iob = IOContext(buf, stream) From e8442283815b4007f3d72ba88944187495b632c8 Mon Sep 17 00:00:00 2001 From: KristofferC Date: Fri, 10 May 2024 11:50:20 +0200 Subject: [PATCH 2/3] Revert "Use StyledStrings for Logging (#51829)" This reverts commit 250916f3a4e515e6edcfcf831e381c38828c4ccc. --- doc/Manifest.toml | 1 - stdlib/Logging/Project.toml | 3 --- stdlib/Logging/src/ConsoleLogger.jl | 33 +++++++++++++---------------- stdlib/Logging/src/Logging.jl | 2 -- stdlib/Logging/test/runtests.jl | 24 ++++++++++----------- stdlib/Manifest.toml | 1 - test/precompile.jl | 1 + 7 files changed, 28 insertions(+), 37 deletions(-) diff --git a/doc/Manifest.toml b/doc/Manifest.toml index cb9d42561be5f..7b8bd47d42a47 100644 --- a/doc/Manifest.toml +++ b/doc/Manifest.toml @@ -144,7 +144,6 @@ uuid = "94ce4f54-9a6c-5748-9c1c-f9c7231a4531" version = "1.17.0+0" [[deps.Logging]] -deps = ["StyledStrings"] uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" version = "1.11.0" diff --git a/stdlib/Logging/Project.toml b/stdlib/Logging/Project.toml index 3fc288e25f0b7..ce69112733d5e 100644 --- a/stdlib/Logging/Project.toml +++ b/stdlib/Logging/Project.toml @@ -2,9 +2,6 @@ name = "Logging" uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" version = "1.11.0" -[deps] -StyledStrings = "f489334b-da3d-4c2e-b8f0-e476e12c162b" - [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/stdlib/Logging/src/ConsoleLogger.jl b/stdlib/Logging/src/ConsoleLogger.jl index 2da16a3e34b70..c4596dd86c3f5 100644 --- a/stdlib/Logging/src/ConsoleLogger.jl +++ b/stdlib/Logging/src/ConsoleLogger.jl @@ -12,10 +12,10 @@ Log levels less than `min_level` are filtered out. Message formatting can be controlled by setting keyword arguments: * `meta_formatter` is a function which takes the log event metadata - `(level, _module, group, id, file, line)` and returns a face name (used in - the constructed [`AnnotatedString`](@ref Base.AnnotatedString)), prefix and - suffix for the log message. The default is to prefix with the log level and - a suffix containing the module, file and line location. + `(level, _module, group, id, file, line)` and returns a color (as would be + passed to printstyled), prefix and suffix for the log message. The + default is to prefix with the log level and a suffix containing the module, + file and line location. * `show_limited` limits the printing of large data structures to something which can fit on the screen by setting the `:limit` `IOContext` key during formatting. @@ -58,10 +58,10 @@ end showvalue(io, ex::Exception) = showerror(io, ex) function default_logcolor(level::LogLevel) - level < Info ? :log_debug : - level < Warn ? :log_info : - level < Error ? :log_warn : - :log_error + level < Info ? Base.debug_color() : + level < Warn ? Base.info_color() : + level < Error ? Base.warn_color() : + Base.error_color() end function default_metafmt(level::LogLevel, _module, group, id, file, line) @@ -103,8 +103,6 @@ function termlength(str) return N end -termlength(str::Base.AnnotatedString) = textwidth(str) - function handle_message(logger::ConsoleLogger, level::LogLevel, message, _module, group, id, filepath, line; kwargs...) @nospecialize @@ -156,7 +154,6 @@ 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)) minsuffixpad = 2 buf = IOBuffer() iob = IOContext(buf, stream) @@ -170,19 +167,19 @@ function handle_message(logger::ConsoleLogger, level::LogLevel, message, _module nonpadwidth = 2 + length(suffix) end for (i, (indent, msg)) in enumerate(msglines) - boxstr = length(msglines) == 1 ? "[" : - i == 1 ? "┌" : - i < length(msglines) ? "│" : - "└" - print(iob, styled"{$color,bold:$boxstr} ") + boxstr = length(msglines) == 1 ? "[ " : + i == 1 ? "┌ " : + i < length(msglines) ? "│ " : + "└ " + printstyled(iob, boxstr, bold=true, color=color) if i == 1 && !isempty(prefix) - print(iob, styled"{$color,bold:$prefix} ") + printstyled(iob, prefix, " ", bold=true, color=color) end print(iob, " "^indent, msg) if i == length(msglines) && !isempty(suffix) npad = max(0, justify_width - nonpadwidth) + minsuffixpad print(iob, " "^npad) - print(iob, styled"{shadow:$suffix}") + printstyled(iob, suffix, color=:light_black) end println(iob) end diff --git a/stdlib/Logging/src/Logging.jl b/stdlib/Logging/src/Logging.jl index 3822bde2e630b..d6f41dd4242cf 100644 --- a/stdlib/Logging/src/Logging.jl +++ b/stdlib/Logging/src/Logging.jl @@ -8,8 +8,6 @@ and available by default. """ module Logging -using StyledStrings - # Import the CoreLogging implementation into Logging as new const bindings. # Doing it this way (rather than with import) makes these symbols accessible to # tab completion. diff --git a/stdlib/Logging/test/runtests.jl b/stdlib/Logging/test/runtests.jl index a244facee3468..176860fcdec63 100644 --- a/stdlib/Logging/test/runtests.jl +++ b/stdlib/Logging/test/runtests.jl @@ -63,24 +63,24 @@ end @testset "Default metadata formatting" begin @test Logging.default_metafmt(Logging.Debug, Base, :g, :i, expanduser("~/somefile.jl"), 42) == - (:log_debug, "Debug:", "@ Base ~/somefile.jl:42") + (:blue, "Debug:", "@ Base ~/somefile.jl:42") @test Logging.default_metafmt(Logging.Info, Main, :g, :i, "a.jl", 1) == - (:log_info, "Info:", "") + (:cyan, "Info:", "") @test Logging.default_metafmt(Logging.Warn, Main, :g, :i, "b.jl", 2) == - (:log_warn, "Warning:", "@ Main b.jl:2") + (:yellow, "Warning:", "@ Main b.jl:2") @test Logging.default_metafmt(Logging.Error, Main, :g, :i, "", 0) == - (:log_error, "Error:", "@ Main :0") + (:light_red, "Error:", "@ Main :0") # formatting of nothing @test Logging.default_metafmt(Logging.Warn, nothing, :g, :i, "b.jl", 2) == - (:log_warn, "Warning:", "@ b.jl:2") + (:yellow, "Warning:", "@ b.jl:2") @test Logging.default_metafmt(Logging.Warn, Main, :g, :i, nothing, 2) == - (:log_warn, "Warning:", "@ Main") + (:yellow, "Warning:", "@ Main") @test Logging.default_metafmt(Logging.Warn, Main, :g, :i, "b.jl", nothing) == - (:log_warn, "Warning:", "@ Main b.jl") + (:yellow, "Warning:", "@ Main b.jl") @test Logging.default_metafmt(Logging.Warn, nothing, :g, :i, nothing, 2) == - (:log_warn, "Warning:", "") + (:yellow, "Warning:", "") @test Logging.default_metafmt(Logging.Warn, Main, :g, :i, "b.jl", 2:5) == - (:log_warn, "Warning:", "@ Main b.jl:2-5") + (:yellow, "Warning:", "@ Main b.jl:2-5") end function dummy_metafmt(level, _module, group, id, file, line) @@ -265,9 +265,9 @@ end # Basic colorization test @test genmsg("line1\nline2", color=true) == """ - \e[36m\e[1m┌\e[39m\e[22m \e[36m\e[1mPREFIX\e[39m\e[22m line1 - \e[36m\e[1m│\e[39m\e[22m line2 - \e[36m\e[1m└\e[39m\e[22m \e[90mSUFFIX\e[39m + \e[36m\e[1m┌ \e[22m\e[39m\e[36m\e[1mPREFIX \e[22m\e[39mline1 + \e[36m\e[1m│ \e[22m\e[39mline2 + \e[36m\e[1m└ \e[22m\e[39m\e[90mSUFFIX\e[39m """ end diff --git a/stdlib/Manifest.toml b/stdlib/Manifest.toml index 8d59f63c4733c..5cf6983c88e5b 100644 --- a/stdlib/Manifest.toml +++ b/stdlib/Manifest.toml @@ -130,7 +130,6 @@ uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" version = "1.11.0" [[deps.Logging]] -deps = ["StyledStrings"] uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" version = "1.11.0" diff --git a/test/precompile.jl b/test/precompile.jl index 0efb5cee06fff..e164c2917d06f 100644 --- a/test/precompile.jl +++ b/test/precompile.jl @@ -447,6 +447,7 @@ precompile_test_harness(false) do dir Dict(Base.PkgId(Base.root_module(Base, :Markdown)) => Base.module_build_id(Base.root_module(Base, :Markdown))), Dict(Base.PkgId(Base.root_module(Base, :JuliaSyntaxHighlighting)) => Base.module_build_id(Base.root_module(Base, :JuliaSyntaxHighlighting))), Dict(Base.PkgId(Base.root_module(Base, :StyledStrings)) => Base.module_build_id(Base.root_module(Base, :StyledStrings))), + # and their dependencies Dict(Base.PkgId(Base.root_module(Base, :Base64)) => Base.module_build_id(Base.root_module(Base, :Base64))), ) From 3638c84f45dd6df9e509cad597121a1076872190 Mon Sep 17 00:00:00 2001 From: KristofferC Date: Fri, 10 May 2024 12:11:42 +0200 Subject: [PATCH 3/3] move ConsoleLogger into Base --- base/Base.jl | 10 ++++++---- {stdlib/Logging/src => base/logging}/ConsoleLogger.jl | 0 base/{ => logging}/logging.jl | 2 ++ base/meta.jl | 2 -- stdlib/Logging/src/Logging.jl | 8 +------- 5 files changed, 9 insertions(+), 13 deletions(-) rename {stdlib/Logging/src => base/logging}/ConsoleLogger.jl (100%) rename base/{ => logging}/logging.jl (99%) diff --git a/base/Base.jl b/base/Base.jl index 3b95b44a33f0b..d4f1b385c43dd 100644 --- a/base/Base.jl +++ b/base/Base.jl @@ -402,13 +402,13 @@ include("weakkeydict.jl") include("scopedvalues.jl") using .ScopedValues -# Logging -include("logging.jl") -using .CoreLogging - # metaprogramming include("meta.jl") +# Logging +include("logging/logging.jl") +using .CoreLogging + include("env.jl") # functions defined in Random @@ -634,6 +634,8 @@ function __init__() if get_bool_env("JULIA_USE_FLISP_PARSER", false) === false JuliaSyntax.enable_in_core!() end + + CoreLogging.global_logger(CoreLogging.ConsoleLogger()) nothing end diff --git a/stdlib/Logging/src/ConsoleLogger.jl b/base/logging/ConsoleLogger.jl similarity index 100% rename from stdlib/Logging/src/ConsoleLogger.jl rename to base/logging/ConsoleLogger.jl diff --git a/base/logging.jl b/base/logging/logging.jl similarity index 99% rename from base/logging.jl rename to base/logging/logging.jl index 75b8eea5051d2..7124ffe25abf2 100644 --- a/base/logging.jl +++ b/base/logging/logging.jl @@ -700,4 +700,6 @@ end _global_logstate = LogState(SimpleLogger()) +include("logging/ConsoleLogger.jl") + end # CoreLogging diff --git a/base/meta.jl b/base/meta.jl index bc07a7efa6c74..e648df29c12f9 100644 --- a/base/meta.jl +++ b/base/meta.jl @@ -5,8 +5,6 @@ Convenience functions for metaprogramming. """ module Meta -using ..CoreLogging - export quot, isexpr, isidentifier, diff --git a/stdlib/Logging/src/Logging.jl b/stdlib/Logging/src/Logging.jl index d6f41dd4242cf..72924e047a9ef 100644 --- a/stdlib/Logging/src/Logging.jl +++ b/stdlib/Logging/src/Logging.jl @@ -68,7 +68,7 @@ Alias for [`LogLevel(1_000_001)`](@ref LogLevel). const AboveMaxLevel = Base.CoreLogging.AboveMaxLevel using Base.CoreLogging: - closed_stream + closed_stream, ConsoleLogger, default_metafmt export AbstractLogger, @@ -92,8 +92,6 @@ export Error, AboveMaxLevel -include("ConsoleLogger.jl") - # The following are also part of the public API, but not exported: # # 1. Log levels: @@ -102,8 +100,4 @@ include("ConsoleLogger.jl") # 2. AbstractLogger message related functions: # handle_message, shouldlog, min_enabled_level, catch_exceptions, -function __init__() - global_logger(ConsoleLogger()) -end - end