@test_logs behavior when using with_logger

When trying to test for logging inside of a custom logger, the @test_logs macro seems to be unable to capture the logs.

Here is an MWE

using Test
using Logging
@test_logs (:error, "test") match_mode = :any Logging.with_logger(Logging.SimpleLogger()) do 
       @error "test"

Which returns empty captured logs

┌ Error: test
└ @ Main REPL[58]:2
Log Test Failed at REPL[58]:1
  Expression: Logging.with_logger(Logging.SimpleLogger()) do 
    #= REPL[58]:2 =# @error "test"
  Log Pattern: :error match_mode = :any
  Captured Logs: 

Anyone has experienced this and knows how to fix?

I’ve just run into this as well. Did you manage to find a solution?


Ah, having just looked through the source code, I understand the problem now:

I thought @test_logs intercepted and analysed stdout/stderr, but really it just wraps a call to with_logger(f, TestLogger). This means of course that it will never see any log messages sent to a different local logger.

That’s a bother. Does anybody have any ideas how one could circumvent this, or whether its worth submitting this as an issue?