Is there a way to disable Pyrogram logging?

Question:

I’m using this library only for couple methods, and it’s kinda annoying that it’s printing a lot of logs beside my own initialization logs.

Tried to get same logger as library gets, "pyrogram.client", and change it’s level – nothing changed.
Also logger.propagate = false doesn’t help.

My friend got no logs from pyrogram by default, though our logger and pyrogram configs are the same.

Asked By: faintReflection

||

Answers:

Try this:

import logging
logging.basicConfig(level=logging.WARNING)

You can also set the level to INFO, but that’s up to you.
Here are all the default levels: https://docs.python.org/3/library/logging.html#logging-levels

Answered By: dieserniko

A way to go, if you do not want to suppress other loggers:

import logging
for name, logger in logging.root.manager.loggerDict.items():
    if name.startswith('pyrogram'):
        logger.setLevel(logging.WARNING)

Optionally, if that’s not enough, replace WARNING with ERROR or CRITICAL.

Answered By: Peter Shevchenko
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.