Closed tdeenes closed 6 months ago
Can you share a bit more about the use case? Maybe it's easier and less of a hack to change the appender to write to /dev/null
or something like that (eg creating appender_void
).
Are you not just asking to set the log level? See ?log_threshold if you set the threshold to WARN, you wouldn't see any level below it: TRACE, DEBUG, INFO, SUCCESS would no longer be shown. Only WARN and above.
FATAL severe error that will prevent the application from continuing
ERROR An error in the application, possibly recoverable
WARN An event that might possible lead to an error
SUCCESS An explicit success event above the INFO level that you want to log
INFO An event for informational purposes
DEBUG A general debugging event
TRACE A fine-grained debug message, typically capturing the flow through the application.
You could set the log_threshold in your test file(s).
Sorry for the substantial delay with my response. @1beb I am well aware of log_threshold
, see the code snippet in the original comment.
@daroczig Indeed, your suggestion with appender_void
is a good idea. However, it still requires to loop through the logging namespaces and set the appender, then revert those changes on exit.
My use case is similar to those of suppressWarnings
or suppressPackageStartupMessages
. e.g.:
pkgC::fooC()
which calls pkgB::fooB()
which calls pkgA::fooA()
. Assume you want to suppress all logger messages within fooC
when you call fooB
, without bothering with the call chain and other logger namespaces. Then in your tests you want to suppress all logger messages (even those of fooC()
) because maybe you know that your unit test will lead fooC
to fail. So suppress_log
would be a convenience utility which would temporarily suppress all messages generated by any logger namespaces when evaluating an expression. Basically not a must-have feature, I agree, so feel free to close the issue.
Sorry for not getting back on this for so long :disappointed:
I am not even sure since when, but now we have with_log_threshold
and also a special log level for not logging anything at all via OFF
, so that two make up appender_void
if I get this right, and can be useful in cases that you have described.
Closing, but pls reopen if I got this wrong.
Oh yeah, I wanted to close this ticket when I saw the new OFF
log level, but forgot to do it. Thanks!
Especially in unit tests it would be helpful to be able to suppress log messages. Something like:
Would you be interested in this feature? The code above is a bit hackish since I introduce a non-supported log level which might break if you change the internals.