slackapi / bolt-python

A framework to build Slack apps using Python

Home Page:https://slack.dev/bolt-python/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why are logging levels explicily set when creating a logger.

Kroppeb opened this issue · comments

def _configure_from_root(new_logger: Logger):
new_logger.disabled = logging.root.disabled
new_logger.level = logging.root.level

Calling logging.getLogger('slack_bolt').setLevel(logging.INFO) or logging.getLogger('slack_bolt').setLevel(logging.INFO) does nothing when the global logging level is set to DEBUG because this library overrides these values for some reason.

Hi @Kroppeb, thanks for writing in! To configure the log-level for the internal loggers, you can pass logger to App constructor: https://slack.dev/bolt-python/api-docs/slack_bolt/app/index.html#slack_bolt.app.App.logger The logger will be used as the base logger internally, so the log level you want to set will be respected for all the internal loggers. This might be a bit surprising to you but we decided to go with this design to support various use cases.

I hope this helps! Let me close this issue now, but whenever you have further to ask, please feel free to write in! 👋

I find this very strange. It seems to me you are implementing a worse version of the stdlibs logging hierarchy internally?

Is there a way to change the logging level of all the internal loggers you could be creating at once. Calling changing the loglevel, or adding or removing handlers/filters after passing it doesn't seem to get propagated to the internal loggers.

There is a logger.getChild() available, it's weird that it's not being used.

Calling changing the loglevel, or adding or removing handlers/filters after passing it doesn't seem to get propagated to the internal loggers.

The only way to set the log level is to call the setter method before passing it to App constructor. In other words, Changing it does not work after passing it but works before passing it.

base_logger = logging.getLogger("my-bolt-logger")
base_logger.setLevel(logging.DEBUG)

app = App(
    token=os.environ.get("SLACK_BOT_TOKEN"),
    logger=base_logger,
)

This could be a limitation to some scenarios, but it should work for most real-world use cases. We don't have any plans to make changes to this mechanism.

Thanks again for asking the question and the feedback.