From 7be0779b6587c4b0db1d0954d4a2a4eeccaddbf2 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Tue, 16 Aug 2022 19:06:23 -0400 Subject: [PATCH] Add root_logger setting to Client.run This allows people one way to use the colour logger globally --- discord/client.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/discord/client.py b/discord/client.py index 8fdf33fb0..8fc932e7f 100644 --- a/discord/client.py +++ b/discord/client.py @@ -810,6 +810,7 @@ class Client: log_handler: Optional[logging.Handler] = MISSING, log_formatter: logging.Formatter = MISSING, log_level: int = MISSING, + root_logger: bool = False, ) -> None: """A blocking call that abstracts away the event loop initialisation from you. @@ -861,6 +862,14 @@ class Client: only controls the library's log level. To control the root logger's level, you can use ``logging.getLogger().setLevel(level)``. + .. versionadded:: 2.0 + root_logger: :class:`bool` + Whether to set up the root logger rather than the library logger. + By default, only the library logger (``'discord'``) is set up. If this + is set to ``True`` then the root logger is set up as well. + + Defaults to ``False``. + .. versionadded:: 2.0 """ @@ -890,6 +899,11 @@ class Client: logger.setLevel(log_level) logger.addHandler(log_handler) + if root_logger: + logger = logging.getLogger() + logger.setLevel(log_level) + logger.addHandler(log_handler) + try: asyncio.run(runner()) except KeyboardInterrupt: