Skip to content

Commit

Permalink
allow custom log level names
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Nov 16, 2023
1 parent 4689850 commit d4e0acf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions base/logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,17 @@ Alias for [`LogLevel(2000)`](@ref LogLevel).
const Error = LogLevel( 2000)
const AboveMaxLevel = LogLevel( 1000001)

# add to this to dict to introduce a log level for printing
const custom_log_levels = Dict{LogLevel,String}()

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")
elseif level in keys(custom_log_levels) print(io, custom_log_levels[level])
else print(io, "LogLevel($(level.level))")
end
end
Expand Down
3 changes: 2 additions & 1 deletion stdlib/Logging/src/Logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ for sym in [
:current_logger,
:global_logger,
:disable_logging,
:SimpleLogger]
:SimpleLogger,
:custom_log_levels]
@eval const $sym = Base.CoreLogging.$sym
end

Expand Down

0 comments on commit d4e0acf

Please sign in to comment.