julia icon indicating copy to clipboard operation
julia copied to clipboard

`Logging.catch_exceptions` should be overridable for tests

Open Drvi opened this issue 2 years ago • 6 comments

It is very useful to know that loggers can't crash a program, but IMO during tests, one would prefer to know the logging is broken by getting an exception. Especially in the CI context, where usually don't inspect the logs if the CI run succeeded.

It would thus be useful if Logging.catch_exceptions could be toggled by an environment variable for testing purposes.

Drvi avatar Nov 13 '23 10:11 Drvi

https://github.com/JuliaLang/julia/blob/9754dbbde5c0b39faa682c390668cf00f9a3df43/stdlib/Test/src/logging.jl#L47-L54

fredrikekre avatar Nov 13 '23 22:11 fredrikekre

Thanks! My worry is that this wouldn't help code that changes the logger internally.

Drvi avatar Nov 14 '23 07:11 Drvi

How do you suggest controlling such code from the outside?

fredrikekre avatar Nov 14 '23 08:11 fredrikekre

Environment variable was my suggestion. If this convention catches on in the Logging module, I think it won't be too difficult for people to adapt their custom loggers as well, if they have an overload for catch_exceptions.

Drvi avatar Nov 14 '23 09:11 Drvi

Hi, so for example

  • Reuse 'JULIA_DEBUG' environment variable, with a new option called, say, 'nocatchexceptions'. The default is messages are caught, so the non-default is this.
  • Change line 71 to being an if statement checking for the env variable.
  • This is good for a use case where the logger needs to be modified after creation, which is possible?

I'm a new contributor btw! Hi!

ghost avatar Nov 20 '23 04:11 ghost

👋 just wanna say, love your github name, @persinammon! 😁 Welcome to the project 😊


+1 to this request though. We want to set a blanket flag to make sure that tests in our build farm would always catch any case where someone introduces a typo that breaks a log-message, but we still don't want an untested typo in a log-message to kill production.

NHDaly avatar May 22 '24 22:05 NHDaly