From 7a91126b76b8b3efb990812d6ab107ef81f58d8c Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Thu, 16 Nov 2023 12:53:16 -0500 Subject: [PATCH 1/9] allow custom log level names & colors --- base/logging.jl | 19 ++++++++++++------- stdlib/Logging/docs/src/index.md | 12 +++++++++++- stdlib/Logging/src/ConsoleLogger.jl | 1 + stdlib/Logging/src/Logging.jl | 12 ++++++++++++ stdlib/Logging/test/runtests.jl | 3 ++- 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/base/logging.jl b/base/logging.jl index f6a34aee2f516..2d0f27dcff57a 100644 --- a/base/logging.jl +++ b/base/logging.jl @@ -162,14 +162,19 @@ const AboveMaxLevel = LogLevel( 1000001) # Global log limiting mechanism for super fast but inflexible global log limiting. const _min_enabled_level = Ref{LogLevel}(Debug) +# add to this to dict to introduce a log level for printing +# i.e. custom_log_levels[LogLevel(-500)] = ("MyLog", :magenta) +const custom_log_levels = Dict{LogLevel,Tuple{String,Symbol}}() + function show(io::IO, level::LogLevel) - if level == BelowMinLevel print(io, "BelowMinLevel") - elseif level == Debug print(io, "Debug") - elseif level == Info print(io, "Info") - elseif level == Warn print(io, "Warn") - elseif level == Error print(io, "Error") - elseif level == AboveMaxLevel print(io, "AboveMaxLevel") - else print(io, "LogLevel($(level.level))") + if level in keys(custom_log_levels) print(io, custom_log_levels[level][1]::String) + elseif level == BelowMinLevel print(io, "BelowMinLevel") + elseif level == Debug print(io, "Debug") + elseif level == Info print(io, "Info") + elseif level == Warn print(io, "Warn") + elseif level == Error print(io, "Error") + elseif level == AboveMaxLevel print(io, "AboveMaxLevel") + else print(io, "LogLevel($(level.level))") end end diff --git a/stdlib/Logging/docs/src/index.md b/stdlib/Logging/docs/src/index.md index 55d24c7ae0a26..3b22e055d4365 100644 --- a/stdlib/Logging/docs/src/index.md +++ b/stdlib/Logging/docs/src/index.md @@ -58,7 +58,7 @@ automatically extracted. Let's examine the user-defined data first: * The *log level* is a broad category for the message that is used for early filtering. There are several standard levels of type [`LogLevel`](@ref); user-defined levels are also possible. - Each is distinct in purpose: + Each built-in is distinct in purpose: - [`Logging.Debug`](@ref) (log level -1000) is information intended for the developer of the program. These events are disabled by default. - [`Logging.Info`](@ref) (log level 0) is for general information to the user. @@ -70,6 +70,15 @@ automatically extracted. Let's examine the user-defined data first: Often this log-level is unneeded as throwing an exception can convey all the required information. + You can also asign printing styles for custom log levels. For instance: + ``` + MyLog = LogLevel(-500) + custom_log_levels[MyLog] = ("MyLog", :magenta) + macro mylog(exs...) Base.CoreLogging.logmsg_code((Base.CoreLogging.@_sourceinfo)..., MyLog, exs...) end + + @mylog "foo" + ``` + * The *message* is an object describing the event. By convention `AbstractString`s passed as messages are assumed to be in markdown format. Other types will be displayed using `print(io, obj)` or `string(obj)` for @@ -298,6 +307,7 @@ Logging.Debug Logging.Info Logging.Warn Logging.Error +Logging.custom_log_levels ``` ### [Processing events with AbstractLogger](@id AbstractLogger-interface) diff --git a/stdlib/Logging/src/ConsoleLogger.jl b/stdlib/Logging/src/ConsoleLogger.jl index 747f8a2b22966..b27752b5711aa 100644 --- a/stdlib/Logging/src/ConsoleLogger.jl +++ b/stdlib/Logging/src/ConsoleLogger.jl @@ -58,6 +58,7 @@ end showvalue(io, ex::Exception) = showerror(io, ex) function default_logcolor(level::LogLevel) + level in keys(custom_log_levels) ? custom_log_levels[level][2]::Symbol : level < Info ? Base.debug_color() : level < Warn ? Base.info_color() : level < Error ? Base.warn_color() : diff --git a/stdlib/Logging/src/Logging.jl b/stdlib/Logging/src/Logging.jl index 0743c650326cc..287fc3b075079 100644 --- a/stdlib/Logging/src/Logging.jl +++ b/stdlib/Logging/src/Logging.jl @@ -55,6 +55,18 @@ Alias for [`LogLevel(2000)`](@ref LogLevel). """ const Error = Base.CoreLogging.Error +""" + custom_log_levels::Dict{LogLevel,Tuple{String,Symbol}} + +Add to this dict to introduce a print style for a custom log. + +For instance: +``` +custom_log_levels[LogLevel(-500)] = ("MyLog", :magenta) +``` +""" +const custom_log_levels = Base.CoreLogging.custom_log_levels + using Base.CoreLogging: closed_stream diff --git a/stdlib/Logging/test/runtests.jl b/stdlib/Logging/test/runtests.jl index 3a793c4e0bc33..7cbe0b465a0e5 100644 --- a/stdlib/Logging/test/runtests.jl +++ b/stdlib/Logging/test/runtests.jl @@ -280,6 +280,7 @@ end end @testset "custom log macro" begin + Logging.custom_log_levels[CustomLog] = ("CustomLog", :magenta) @test_logs (CustomLog, "a") min_level=CustomLog @customlog "a" buf = IOBuffer() @@ -289,7 +290,7 @@ end with_logger(logger) do @customlog "a" end - @test occursin("LogLevel(-500): a", String(take!(buf))) + @test occursin("CustomLog: a", String(take!(buf))) end end From a80071e19a1992043bb4f51162a067868f7a0be4 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Thu, 28 Dec 2023 14:11:21 -0500 Subject: [PATCH 2/9] add @create_log_macro for easily making log macros --- NEWS.md | 5 +++++ base/logging.jl | 35 +++++++++++++++++++++++++---- stdlib/Logging/docs/src/index.md | 14 +++++++----- stdlib/Logging/src/ConsoleLogger.jl | 2 +- stdlib/Logging/src/Logging.jl | 2 ++ stdlib/Logging/test/runtests.jl | 20 +++++++++++------ 6 files changed, 60 insertions(+), 18 deletions(-) diff --git a/NEWS.md b/NEWS.md index d5ef405b7a913..ab5410ff1014f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -116,6 +116,11 @@ Standard library changes argument is the output of `bunchkaufman` or `lu` ([#50471]). * Structured matrices now retain either the axes of the parent (for `Symmetric`/`Hermitian`/`AbstractTriangular`/`UpperHessenberg`), or that of the principal diagonal (for banded matrices) ([#52480]). +#### Logging +* New `@create_log_macro` macro for creating new log macros like `@info`, `@warn` etc. For instance + `@create_log_macro MyLog 1500 :magenta` will create `@mylog` to be used like `@mylog "hello"` which + will show as `┌ MyLog: hello` etc. ([#52196]) + #### Printf #### Profile diff --git a/base/logging.jl b/base/logging.jl index 2d0f27dcff57a..4f20975c06982 100644 --- a/base/logging.jl +++ b/base/logging.jl @@ -162,12 +162,10 @@ const AboveMaxLevel = LogLevel( 1000001) # Global log limiting mechanism for super fast but inflexible global log limiting. const _min_enabled_level = Ref{LogLevel}(Debug) -# add to this to dict to introduce a log level for printing -# i.e. custom_log_levels[LogLevel(-500)] = ("MyLog", :magenta) -const custom_log_levels = Dict{LogLevel,Tuple{String,Symbol}}() +const custom_log_levels = Dict{LogLevel,Tuple{Symbol,Union{Symbol,Int}}}() function show(io::IO, level::LogLevel) - if level in keys(custom_log_levels) print(io, custom_log_levels[level][1]::String) + if level in keys(custom_log_levels) print(io, custom_log_levels[level][1]) elseif level == BelowMinLevel print(io, "BelowMinLevel") elseif level == Debug print(io, "Debug") elseif level == Info print(io, "Info") @@ -694,4 +692,33 @@ end _global_logstate = LogState(SimpleLogger()) +""" + @create_log_macro(name::Symbol, level::Int, color::Union{Int,Symbol}) + +Creates a custom log macro like `@info`, `@warn` etc. with a given `name`, `level` and +`color`. The macro created is named with the lowercase form of `name` but the given form +is used for the printing. + +See `Base.text_colors` for recognized color values. + +```julia-repl +julia> @create_log_macro(:MyLog, 200, :magenta) +@mylog (macro with 1 method) + +julia> @mylog "hello" +[ MyLog: hello +``` +""" +macro create_log_macro(name, level, color) + macro_name = Symbol(lowercase(string(name))) + macro_string = QuoteNode(name) + loglevel = LogLevel(level) + quote + custom_log_levels[$(esc(loglevel))] = ($(macro_string), $(esc(color))) + macro $(esc(macro_name))(exs...) + $logmsg_code(($@_sourceinfo)..., $(esc(loglevel)), exs...) + end + end +end + end # CoreLogging diff --git a/stdlib/Logging/docs/src/index.md b/stdlib/Logging/docs/src/index.md index 3b22e055d4365..4b1eb7bb19aa6 100644 --- a/stdlib/Logging/docs/src/index.md +++ b/stdlib/Logging/docs/src/index.md @@ -70,13 +70,15 @@ automatically extracted. Let's examine the user-defined data first: Often this log-level is unneeded as throwing an exception can convey all the required information. - You can also asign printing styles for custom log levels. For instance: - ``` - MyLog = LogLevel(-500) - custom_log_levels[MyLog] = ("MyLog", :magenta) - macro mylog(exs...) Base.CoreLogging.logmsg_code((Base.CoreLogging.@_sourceinfo)..., MyLog, exs...) end + You can also create logging macros for custom log levels. For instance: + ```julia-repl + julia> using Logging + + julia> @create_log_macro(:MyLog, 200, :magenta) + @mylog (macro with 1 method) - @mylog "foo" + julia> @mylog "hello" + [ MyLog: hello ``` * The *message* is an object describing the event. By convention diff --git a/stdlib/Logging/src/ConsoleLogger.jl b/stdlib/Logging/src/ConsoleLogger.jl index b27752b5711aa..1d45296c907d1 100644 --- a/stdlib/Logging/src/ConsoleLogger.jl +++ b/stdlib/Logging/src/ConsoleLogger.jl @@ -58,7 +58,7 @@ end showvalue(io, ex::Exception) = showerror(io, ex) function default_logcolor(level::LogLevel) - level in keys(custom_log_levels) ? custom_log_levels[level][2]::Symbol : + level in keys(custom_log_levels) ? custom_log_levels[level][2] : level < Info ? Base.debug_color() : level < Warn ? Base.info_color() : level < Error ? Base.warn_color() : diff --git a/stdlib/Logging/src/Logging.jl b/stdlib/Logging/src/Logging.jl index 287fc3b075079..7fe4f7db1cf39 100644 --- a/stdlib/Logging/src/Logging.jl +++ b/stdlib/Logging/src/Logging.jl @@ -21,6 +21,7 @@ for sym in [ Symbol("@warn"), Symbol("@error"), Symbol("@logmsg"), + Symbol("@create_log_macro"), :with_logger, :current_logger, :global_logger, @@ -79,6 +80,7 @@ export @warn, @error, @logmsg, + @create_log_macro, with_logger, current_logger, global_logger, diff --git a/stdlib/Logging/test/runtests.jl b/stdlib/Logging/test/runtests.jl index 7cbe0b465a0e5..ed637cc6c1f39 100644 --- a/stdlib/Logging/test/runtests.jl +++ b/stdlib/Logging/test/runtests.jl @@ -6,10 +6,6 @@ import Logging: min_enabled_level, shouldlog, handle_message @noinline func1() = backtrace() -# see "custom log macro" testset -CustomLog = LogLevel(-500) -macro customlog(exs...) Base.CoreLogging.logmsg_code((Base.CoreLogging.@_sourceinfo)..., esc(CustomLog), exs...) end - @testset "Logging" begin @testset "Core" begin @@ -280,17 +276,27 @@ end end @testset "custom log macro" begin - Logging.custom_log_levels[CustomLog] = ("CustomLog", :magenta) - @test_logs (CustomLog, "a") min_level=CustomLog @customlog "a" + @create_log_macro CustomLog -500 :magenta + + llevel = LogLevel(-500) + + @test_logs (llevel, "a") min_level=llevel @customlog "a" buf = IOBuffer() io = IOContext(buf, :displaysize=>(30,80), :color=>false) - logger = ConsoleLogger(io, CustomLog) + logger = ConsoleLogger(io, llevel) with_logger(logger) do @customlog "a" end @test occursin("CustomLog: a", String(take!(buf))) + + @create_log_macro CustomLog2 1500 1 + + with_logger(logger) do + @customlog2 "hello" + end + @test occursin("CustomLog2: a", String(take!(buf))) end end From a910e8a0c505650aaefe149f1ebc11936bc4e6ac Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Fri, 29 Dec 2023 19:13:23 -0500 Subject: [PATCH 3/9] fix tests --- base/logging.jl | 6 ++++++ stdlib/Logging/test/runtests.jl | 15 ++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/base/logging.jl b/base/logging.jl index 4f20975c06982..b23b5aed60299 100644 --- a/base/logging.jl +++ b/base/logging.jl @@ -713,6 +713,12 @@ macro create_log_macro(name, level, color) macro_name = Symbol(lowercase(string(name))) macro_string = QuoteNode(name) loglevel = LogLevel(level) + if loglevel in (BelowMinLevel, Debug, Info, Warn, Error, AboveMaxLevel) + throw(ArgumentError("Cannot use the same log level as a built in log macro")) + end + if haskey(custom_log_levels, loglevel) + throw(ArgumentError("Custom log macro already exists for given log level")) + end quote custom_log_levels[$(esc(loglevel))] = ($(macro_string), $(esc(color))) macro $(esc(macro_name))(exs...) diff --git a/stdlib/Logging/test/runtests.jl b/stdlib/Logging/test/runtests.jl index ed637cc6c1f39..e7b3fbca2098d 100644 --- a/stdlib/Logging/test/runtests.jl +++ b/stdlib/Logging/test/runtests.jl @@ -6,6 +6,10 @@ import Logging: min_enabled_level, shouldlog, handle_message @noinline func1() = backtrace() +# see "custom log macro" testset +@create_log_macro CustomLog1 -500 :magenta +@create_log_macro CustomLog2 1500 1 + @testset "Logging" begin @testset "Core" begin @@ -276,27 +280,24 @@ end end @testset "custom log macro" begin - @create_log_macro CustomLog -500 :magenta - llevel = LogLevel(-500) - @test_logs (llevel, "a") min_level=llevel @customlog "a" + @test_logs (llevel, "foo") min_level=llevel @customlog1 "foo" buf = IOBuffer() io = IOContext(buf, :displaysize=>(30,80), :color=>false) logger = ConsoleLogger(io, llevel) with_logger(logger) do - @customlog "a" + @customlog1 "foo" end - @test occursin("CustomLog: a", String(take!(buf))) + @test occursin("CustomLog1: foo", String(take!(buf))) - @create_log_macro CustomLog2 1500 1 with_logger(logger) do @customlog2 "hello" end - @test occursin("CustomLog2: a", String(take!(buf))) + @test occursin("CustomLog2: hello", String(take!(buf))) end end From 78f436977d2e0bc766a1d971117b91e28e41bf3d Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Sat, 30 Dec 2023 07:46:45 -0500 Subject: [PATCH 4/9] move macro to Logging --- base/logging.jl | 35 ---------------------------------- stdlib/Logging/src/Logging.jl | 36 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/base/logging.jl b/base/logging.jl index b23b5aed60299..adbc2caf1c2f0 100644 --- a/base/logging.jl +++ b/base/logging.jl @@ -692,39 +692,4 @@ end _global_logstate = LogState(SimpleLogger()) -""" - @create_log_macro(name::Symbol, level::Int, color::Union{Int,Symbol}) - -Creates a custom log macro like `@info`, `@warn` etc. with a given `name`, `level` and -`color`. The macro created is named with the lowercase form of `name` but the given form -is used for the printing. - -See `Base.text_colors` for recognized color values. - -```julia-repl -julia> @create_log_macro(:MyLog, 200, :magenta) -@mylog (macro with 1 method) - -julia> @mylog "hello" -[ MyLog: hello -``` -""" -macro create_log_macro(name, level, color) - macro_name = Symbol(lowercase(string(name))) - macro_string = QuoteNode(name) - loglevel = LogLevel(level) - if loglevel in (BelowMinLevel, Debug, Info, Warn, Error, AboveMaxLevel) - throw(ArgumentError("Cannot use the same log level as a built in log macro")) - end - if haskey(custom_log_levels, loglevel) - throw(ArgumentError("Custom log macro already exists for given log level")) - end - quote - custom_log_levels[$(esc(loglevel))] = ($(macro_string), $(esc(color))) - macro $(esc(macro_name))(exs...) - $logmsg_code(($@_sourceinfo)..., $(esc(loglevel)), exs...) - end - end -end - end # CoreLogging diff --git a/stdlib/Logging/src/Logging.jl b/stdlib/Logging/src/Logging.jl index 7fe4f7db1cf39..a87fec87ad631 100644 --- a/stdlib/Logging/src/Logging.jl +++ b/stdlib/Logging/src/Logging.jl @@ -21,7 +21,6 @@ for sym in [ Symbol("@warn"), Symbol("@error"), Symbol("@logmsg"), - Symbol("@create_log_macro"), :with_logger, :current_logger, :global_logger, @@ -30,6 +29,41 @@ for sym in [ @eval const $sym = Base.CoreLogging.$sym end +""" + @create_log_macro(name::Symbol, level::Int, color::Union{Int,Symbol}) + +Creates a custom log macro like `@info`, `@warn` etc. with a given `name`, `level` and +`color`. The macro created is named with the lowercase form of `name` but the given form +is used for the printing. + +See `Base.text_colors` for recognized color values. + +```julia-repl +julia> @create_log_macro(:MyLog, 200, :magenta) +@mylog (macro with 1 method) + +julia> @mylog "hello" +[ MyLog: hello +``` +""" +macro create_log_macro(name, level, color) + macro_name = Symbol(lowercase(string(name))) + macro_string = QuoteNode(name) + loglevel = LogLevel(level) + if loglevel in (BelowMinLevel, Debug, Info, Warn, Error, AboveMaxLevel) + throw(ArgumentError("Cannot use the same log level as a built in log macro")) + end + if haskey(custom_log_levels, loglevel) + throw(ArgumentError("Custom log macro already exists for given log level")) + end + quote + $(Base.CoreLogging.custom_log_levels)[$(esc(loglevel))] = ($(macro_string), $(esc(color))) + macro $(esc(macro_name))(exs...) + $(Base.CoreLogging.logmsg_code)(($(Base.CoreLogging.@_sourceinfo))..., $(esc(loglevel)), exs...) + end + end +end + # LogLevel aliases (re-)documented here (JuliaLang/julia#40978) """ Debug From fb49856aa87efeb2663757324dab724884c0261f Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Sat, 30 Dec 2023 10:23:57 -0500 Subject: [PATCH 5/9] Update index.md --- stdlib/Logging/docs/src/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/Logging/docs/src/index.md b/stdlib/Logging/docs/src/index.md index 4b1eb7bb19aa6..8d6b6a3d8c969 100644 --- a/stdlib/Logging/docs/src/index.md +++ b/stdlib/Logging/docs/src/index.md @@ -74,7 +74,7 @@ automatically extracted. Let's examine the user-defined data first: ```julia-repl julia> using Logging - julia> @create_log_macro(:MyLog, 200, :magenta) + julia> @create_log_macro MyLog 200 :magenta @mylog (macro with 1 method) julia> @mylog "hello" From bd9064de9d3328fc997b0277406ebe5ca8ad2c06 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Mon, 1 Jan 2024 10:58:15 -0500 Subject: [PATCH 6/9] suggestions Co-Authored-By: Frames White --- base/logging.jl | 1 + stdlib/Logging/docs/src/index.md | 4 ++-- stdlib/Logging/src/Logging.jl | 12 ------------ 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/base/logging.jl b/base/logging.jl index adbc2caf1c2f0..d2964bb910ff9 100644 --- a/base/logging.jl +++ b/base/logging.jl @@ -162,6 +162,7 @@ const AboveMaxLevel = LogLevel( 1000001) # Global log limiting mechanism for super fast but inflexible global log limiting. const _min_enabled_level = Ref{LogLevel}(Debug) +# stored as LogLevel => (name, color) const custom_log_levels = Dict{LogLevel,Tuple{Symbol,Union{Symbol,Int}}}() function show(io::IO, level::LogLevel) diff --git a/stdlib/Logging/docs/src/index.md b/stdlib/Logging/docs/src/index.md index 8d6b6a3d8c969..50f7339f7b647 100644 --- a/stdlib/Logging/docs/src/index.md +++ b/stdlib/Logging/docs/src/index.md @@ -58,7 +58,7 @@ automatically extracted. Let's examine the user-defined data first: * The *log level* is a broad category for the message that is used for early filtering. There are several standard levels of type [`LogLevel`](@ref); user-defined levels are also possible. - Each built-in is distinct in purpose: + Each built-in log level is distinct in purpose: - [`Logging.Debug`](@ref) (log level -1000) is information intended for the developer of the program. These events are disabled by default. - [`Logging.Info`](@ref) (log level 0) is for general information to the user. @@ -70,7 +70,7 @@ automatically extracted. Let's examine the user-defined data first: Often this log-level is unneeded as throwing an exception can convey all the required information. - You can also create logging macros for custom log levels. For instance: + You can create logging macros for custom log levels. For instance: ```julia-repl julia> using Logging diff --git a/stdlib/Logging/src/Logging.jl b/stdlib/Logging/src/Logging.jl index a87fec87ad631..3af823a84d52e 100644 --- a/stdlib/Logging/src/Logging.jl +++ b/stdlib/Logging/src/Logging.jl @@ -90,18 +90,6 @@ Alias for [`LogLevel(2000)`](@ref LogLevel). """ const Error = Base.CoreLogging.Error -""" - custom_log_levels::Dict{LogLevel,Tuple{String,Symbol}} - -Add to this dict to introduce a print style for a custom log. - -For instance: -``` -custom_log_levels[LogLevel(-500)] = ("MyLog", :magenta) -``` -""" -const custom_log_levels = Base.CoreLogging.custom_log_levels - using Base.CoreLogging: closed_stream From b196e65bdf9b6bd3266d53ceb410a86e31407bdc Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Mon, 1 Jan 2024 10:59:50 -0500 Subject: [PATCH 7/9] text_colors note tweak --- stdlib/Logging/src/Logging.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/Logging/src/Logging.jl b/stdlib/Logging/src/Logging.jl index 3af823a84d52e..afa9d7689f091 100644 --- a/stdlib/Logging/src/Logging.jl +++ b/stdlib/Logging/src/Logging.jl @@ -36,7 +36,7 @@ Creates a custom log macro like `@info`, `@warn` etc. with a given `name`, `leve `color`. The macro created is named with the lowercase form of `name` but the given form is used for the printing. -See `Base.text_colors` for recognized color values. +The available color keys can be seen by typing `Base.text_colors` in the help mode of the REPL ```julia-repl julia> @create_log_macro(:MyLog, 200, :magenta) From 9345c5d8e2215ce43ce260f5268738e424c2559e Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Mon, 1 Jan 2024 12:31:21 -0500 Subject: [PATCH 8/9] fixup --- stdlib/Logging/docs/src/index.md | 2 +- stdlib/Logging/src/Logging.jl | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/stdlib/Logging/docs/src/index.md b/stdlib/Logging/docs/src/index.md index 50f7339f7b647..882c66af2baef 100644 --- a/stdlib/Logging/docs/src/index.md +++ b/stdlib/Logging/docs/src/index.md @@ -309,7 +309,7 @@ Logging.Debug Logging.Info Logging.Warn Logging.Error -Logging.custom_log_levels +Logging.@create_log_macro ``` ### [Processing events with AbstractLogger](@id AbstractLogger-interface) diff --git a/stdlib/Logging/src/Logging.jl b/stdlib/Logging/src/Logging.jl index afa9d7689f091..83e93ee396361 100644 --- a/stdlib/Logging/src/Logging.jl +++ b/stdlib/Logging/src/Logging.jl @@ -21,6 +21,7 @@ for sym in [ Symbol("@warn"), Symbol("@error"), Symbol("@logmsg"), + :custom_log_levels, :with_logger, :current_logger, :global_logger, @@ -57,7 +58,7 @@ macro create_log_macro(name, level, color) throw(ArgumentError("Custom log macro already exists for given log level")) end quote - $(Base.CoreLogging.custom_log_levels)[$(esc(loglevel))] = ($(macro_string), $(esc(color))) + $(custom_log_levels)[$(esc(loglevel))] = ($(macro_string), $(esc(color))) macro $(esc(macro_name))(exs...) $(Base.CoreLogging.logmsg_code)(($(Base.CoreLogging.@_sourceinfo))..., $(esc(loglevel)), exs...) end From 4b46117c05e7f91c3e8014bf7d05de2165ca24d6 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Mon, 1 Jan 2024 14:46:58 -0500 Subject: [PATCH 9/9] Update logging.jl Co-authored-by: Jacob Quinn --- base/logging.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/logging.jl b/base/logging.jl index d2964bb910ff9..1853caa16148c 100644 --- a/base/logging.jl +++ b/base/logging.jl @@ -166,7 +166,7 @@ const _min_enabled_level = Ref{LogLevel}(Debug) const custom_log_levels = Dict{LogLevel,Tuple{Symbol,Union{Symbol,Int}}}() function show(io::IO, level::LogLevel) - if level in keys(custom_log_levels) print(io, custom_log_levels[level][1]) + if haskey(custom_log_levels, level) print(io, custom_log_levels[level][1]) elseif level == BelowMinLevel print(io, "BelowMinLevel") elseif level == Debug print(io, "Debug") elseif level == Info print(io, "Info")