Add root_logger setting to Client.run

This allows people one way to use the colour logger globally
This commit is contained in:
Rapptz 2022-08-16 19:06:23 -04:00
parent f12cdd5f90
commit 7be0779b65

View File

@ -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: