Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export standard log levels from Logging stdlib. #40980

Merged
merged 1 commit into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ Standard library changes

#### DelimitedFiles

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


Deprecated or removed
---------------------
Expand Down
2 changes: 1 addition & 1 deletion base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ show_supertypes(typ::DataType) = show_supertypes(stdout, typ)

Prints one or more expressions, and their results, to `stdout`, and returns the last result.

See also: [`show`](@ref), [`@info`](@ref Logging), [`println`](@ref).
See also: [`show`](@ref), [`@info`](@ref man-logging), [`println`](@ref).

# Examples
```jldoctest
Expand Down
2 changes: 1 addition & 1 deletion doc/src/manual/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ should have at the terminal.

### `JULIA_DEBUG`

Enable debug logging for a file or module, see [`Logging`](@ref Logging) for more information.
Enable debug logging for a file or module, see [`Logging`](@ref man-logging) for more information.

### `JULIA_GC_ALLOC_POOL`, `JULIA_GC_ALLOC_OTHER`, `JULIA_GC_ALLOC_PRINT`

Expand Down
2 changes: 1 addition & 1 deletion stdlib/Logging/docs/src/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Logging
# [Logging](@id man-logging)

The [`Logging`](@ref Logging.Logging) module provides a way to record the history and progress of a
computation as a log of events. Events are created by inserting a logging
Expand Down
8 changes: 7 additions & 1 deletion stdlib/Logging/src/Logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ export
global_logger,
disable_logging,
SimpleLogger,
ConsoleLogger
ConsoleLogger,
BelowMinLevel,
Debug,
Info,
Warn,
Error,
AboveMaxLevel

include("ConsoleLogger.jl")

Expand Down
16 changes: 16 additions & 0 deletions stdlib/Logging/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,20 @@ end

end

@testset "exported names" begin
m = Module(:ExportedLoggingNames)
include_string(m, """
using Logging
function run()
BelowMinLevel === Logging.BelowMinLevel &&
Debug === Logging.Debug &&
Info === Logging.Info &&
Warn === Logging.Warn &&
Error === Logging.Error &&
AboveMaxLevel === Logging.AboveMaxLevel
end
""")
@test m.run()
end

end
17 changes: 8 additions & 9 deletions stdlib/Test/src/logging.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

using Logging
import Logging: Info,
shouldlog, handle_message, min_enabled_level, catch_exceptions
using Logging: Logging, AbstractLogger, LogLevel, Info, with_logger
import Base: occursin

#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -30,22 +28,23 @@ mutable struct TestLogger <: AbstractLogger
shouldlog_args
end

TestLogger(; min_level=Info, catch_exceptions=false) = TestLogger(LogRecord[], min_level, catch_exceptions, nothing)
min_enabled_level(logger::TestLogger) = logger.min_level
TestLogger(; min_level=Info, catch_exceptions=false) =
TestLogger(LogRecord[], min_level, catch_exceptions, nothing)
Logging.min_enabled_level(logger::TestLogger) = logger.min_level

function shouldlog(logger::TestLogger, level, _module, group, id)
function Logging.shouldlog(logger::TestLogger, level, _module, group, id)
logger.shouldlog_args = (level, _module, group, id)
true
end

function handle_message(logger::TestLogger, level, msg, _module,
group, id, file, line; kwargs...)
function Logging.handle_message(logger::TestLogger, level, msg, _module,
group, id, file, line; kwargs...)
@nospecialize
push!(logger.logs, LogRecord(level, msg, _module, group, id, file, line, kwargs))
end

# Catch exceptions for the test logger only if specified
catch_exceptions(logger::TestLogger) = logger.catch_exceptions
Logging.catch_exceptions(logger::TestLogger) = logger.catch_exceptions

function collect_test_logs(f; kwargs...)
logger = TestLogger(; kwargs...)
Expand Down