How to disable logging?
PixelSymbols opened this issue · comments
SYM commented
Could not find any info how to disable logging in docs
Hynek Schlawack commented
There's multiple ways; the easiest ist probably:
def drop_all(*_, **_):
raise structlog.DropEvent
structlog.configure(processors=[drop_all])
SYM commented
would be cool if you could just call disable
and enable
methods on logger and it would work.
Hynek Schlawack commented
Since structlog loggers are immutable, that is impossible. But you can do something like:
def drop_all(*_, ed):
if "disabled" in ed:
raise structlog.DropEvent
return ed
log = logger.bind(disabled=True)
…
log = logger.unbind("disabled")