Skip to content

Commit

Permalink
Export standard log levels from Logging stdlib.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Jun 17, 2021
1 parent 6dfa690 commit e1f7e87
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 13 deletions.
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
12 changes: 12 additions & 0 deletions stdlib/Logging/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,16 @@ end

end

module ExportedLoggingNames
# Test exported names from Logging
using Logging
using Test: @test
@test BelowMinLevel === Logging.BelowMinLevel
@test Debug === Logging.Debug
@test Info === Logging.Info
@test Warn === Logging.Warn
@test Error === Logging.Error
@test AboveMaxLevel === Logging.AboveMaxLevel
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

0 comments on commit e1f7e87

Please sign in to comment.