[Python] How can I change the debug-level and format for the Quart (i.e. hypercorn) logger?

Discussão em 'Python' iniciado por Stack, Abril 29, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to set the level and format for the loggers used by the Quart module the way I did it successfully for other 'foreign' loggers:

    • by running basicConfig and implicitly setting up the root-logger or later
    • by running logging.getLogger("urllib3.connectionpool").setLevel(logging.INFO) to get and modify an existing logger

    However those approaches don't work for the loggers spawned by Quart. Neither are those affected by basicConfig nor can I set the level. Output will always look like this:

    [2023-07-28 16:17:12 +0200] [1254610] [INFO] Running on http://0.0.0.0:5432 (CTRL + C to quit)


    Setting breakpoints in logging/__init__.py let the program break on log messages by hypercorn.error (so it seems to use the same module), but setting the level like this

    logging.getLogger("hypercorn.error").setLevel(logging.WARNING)


    doesn't have any effect.

    The doc says I should use dictConfig, so I've added

    dictConfig({
    'version': 1,
    'loggers': {
    'quart.app': {'level': 'ERROR'},
    'hypercorn.error': {'level': 'ERROR'},
    },
    })


    .. no effect

    I found https://github.com/pgjones/hypercorn/issues/120, and tried

    logger = logging.getLogger("hypercorn.error")
    logger.addHandler(my_own_handler)
    logger.setLevel(logging.WARNING)
    logger.propagate = False


    but also without effect.

    What else can I try?

    Continue reading...

Compartilhe esta Página