diff --git a/base/logging/logging.jl b/base/logging/logging.jl index e0cc936bfbf3f..41721e84cc934 100644 --- a/base/logging/logging.jl +++ b/base/logging/logging.jl @@ -420,12 +420,13 @@ function logmsg_code(_module, file, line, level, message, exs...) end end -@noinline function handle_message_nothrow(logger, level, msg, _module, group, id, file, - line, args...; kwargs...) +@noinline function handle_message_nothrow(logger, level, msg, _module, group, id, file, line; kwargs...) + @nospecialize try @invokelatest handle_message( - logger, level, msg, _module, group, id, file, line, args...; + logger, level, msg, _module, group, id, file, line; kwargs...) + catch err @invokelatest logging_error(logger, level, _module, group, id, file, line, err, true) end diff --git a/test/corelogging.jl b/test/corelogging.jl index b10630fa2fdff..64475c8252067 100644 --- a/test/corelogging.jl +++ b/test/corelogging.jl @@ -115,26 +115,11 @@ end end end @testset "Log message handle_message exception handling" begin - function capture_stderr(func) - fname = tempname() - f = open(fname, "w") - redirect_stderr(f) do - func() - end - close(f) - buf = read(fname) - rm(fname) - String(buf) - end - # Exceptions in log handling (printing) of msg are caught by default struct Foo end Base.show(::IO, ::Foo) = 1 รท 0 - out = capture_stderr() do - @info Foo() - end - @test occursin("Error: Exception while generating log record in module Main at", out) - @test occursin("DivideError: integer division error", out) + + @test_warn r"Error: Exception while generating log record in module Main at.*DivideError: integer division error" @info Foo() # Exceptions in log handling (printing) of attributes are caught by default out = capture_stderr() do