Skip to content

Commit 3541609

Browse files
committed
Export standard log levels from Logging stdlib.
1 parent 6dfa690 commit 3541609

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

NEWS.md

+4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ Standard library changes
7171

7272
#### DelimitedFiles
7373

74+
#### Logging
75+
* The standard log levels `BelowMinLevel`, `Debug`, `Info`, `Warn`, `Error`,
76+
and `AboveMaxLevel` are now exported from the Logging stdlib ([#40980]).
77+
7478

7579
Deprecated or removed
7680
---------------------

stdlib/Logging/src/Logging.jl

+7-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@ export
7272
global_logger,
7373
disable_logging,
7474
SimpleLogger,
75-
ConsoleLogger
75+
ConsoleLogger,
76+
BelowMinLevel,
77+
Debug,
78+
Info,
79+
Warn,
80+
Error,
81+
AboveMaxLevel
7682

7783
include("ConsoleLogger.jl")
7884

stdlib/Logging/test/runtests.jl

+12
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,16 @@ end
259259

260260
end
261261

262+
module ExportedLoggingNames
263+
using Logging
264+
f() = (BelowMinLevel, Debug, Info, Warn, Error, AboveMaxLevel, LogLevel)
265+
end
266+
267+
@testset "Exported names" begin
268+
import .ExportedLoggingNames
269+
@test ExportedLoggingNames.f() ==
270+
(Logging.BelowMinLevel, Logging.Debug, Logging.Info, Logging.Warn,
271+
Logging.Error, Logging.AboveMaxLevel, Logging.LogLevel)
272+
end
273+
262274
end

stdlib/Test/src/logging.jl

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3-
using Logging
4-
import Logging: Info,
5-
shouldlog, handle_message, min_enabled_level, catch_exceptions
3+
using Logging: Logging, AbstractLogger, LogLevel, Info, with_logger
64
import Base: occursin
75

86
#-------------------------------------------------------------------------------
@@ -30,22 +28,23 @@ mutable struct TestLogger <: AbstractLogger
3028
shouldlog_args
3129
end
3230

33-
TestLogger(; min_level=Info, catch_exceptions=false) = TestLogger(LogRecord[], min_level, catch_exceptions, nothing)
34-
min_enabled_level(logger::TestLogger) = logger.min_level
31+
TestLogger(; min_level=Info, catch_exceptions=false) =
32+
TestLogger(LogRecord[], min_level, catch_exceptions, nothing)
33+
Logging.min_enabled_level(logger::TestLogger) = logger.min_level
3534

36-
function shouldlog(logger::TestLogger, level, _module, group, id)
35+
function Logging.shouldlog(logger::TestLogger, level, _module, group, id)
3736
logger.shouldlog_args = (level, _module, group, id)
3837
true
3938
end
4039

41-
function handle_message(logger::TestLogger, level, msg, _module,
42-
group, id, file, line; kwargs...)
40+
function Logging.handle_message(logger::TestLogger, level, msg, _module,
41+
group, id, file, line; kwargs...)
4342
@nospecialize
4443
push!(logger.logs, LogRecord(level, msg, _module, group, id, file, line, kwargs))
4544
end
4645

4746
# Catch exceptions for the test logger only if specified
48-
catch_exceptions(logger::TestLogger) = logger.catch_exceptions
47+
Logging.catch_exceptions(logger::TestLogger) = logger.catch_exceptions
4948

5049
function collect_test_logs(f; kwargs...)
5150
logger = TestLogger(; kwargs...)

0 commit comments

Comments
 (0)