hynek / structlog

Simple, powerful, and fast logging for Python.

Home Page:https://www.structlog.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to disable logging?

PixelSymbols opened this issue · comments

commented

Could not find any info how to disable logging in docs

There's multiple ways; the easiest ist probably:

def drop_all(*_, **_):
    raise structlog.DropEvent

structlog.configure(processors=[drop_all])
commented

would be cool if you could just call disable and enable methods on logger and it would work.

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")