|
1 | 1 | import contextlib |
| 2 | +import logging |
2 | 3 | import re |
3 | 4 | import sys |
4 | 5 | from asyncio import AbstractEventLoop, CancelledError, get_event_loop, iscoroutinefunction |
5 | 6 | from functools import wraps |
6 | 7 | from importlib import import_module |
7 | 8 | from importlib.util import resolve_name |
8 | 9 | from inspect import getmembers |
9 | | -from logging import Logger |
10 | 10 | from types import ModuleType |
11 | 11 | from typing import Any, Callable, Coroutine, Dict, List, Optional, Tuple, Union |
12 | 12 |
|
|
27 | 27 | from .models.command import ApplicationCommand, Choice, Command, Option |
28 | 28 | from .models.component import Button, Modal, SelectMenu |
29 | 29 |
|
30 | | -log: Logger = get_logger("client") |
| 30 | +log: logging.Logger = get_logger("client") |
31 | 31 |
|
32 | 32 | __all__ = ( |
33 | 33 | "Client", |
@@ -58,6 +58,8 @@ class Client: |
58 | 58 | :type default_scope?: Optional[Union[int, Guild, List[int], List[Guild]]] |
59 | 59 | :param disable_sync?: Controls whether synchronization in the user-facing API should be automatic or not. |
60 | 60 | :type disable_sync?: Optional[bool] |
| 61 | + :param logging?: Set to ``True`` to enable debug logging or set to a log level to use a specific level |
| 62 | + :type logging?: Optional[Union[bool, logging.DEBUG, logging.INFO, logging.NOTSET, logging.WARNING, logging.ERROR, logging.CRITICAL]] |
61 | 63 |
|
62 | 64 | :ivar AbstractEventLoop _loop: The asynchronous event loop of the client. |
63 | 65 | :ivar HTTPClient _http: The user-facing HTTP connection to the Web API, as its own separate client. |
@@ -102,6 +104,21 @@ def __init__( |
102 | 104 | ] |
103 | 105 | self._default_scope = convert_list(int)(self._default_scope) |
104 | 106 |
|
| 107 | + if _logging := kwargs.get("logging"): |
| 108 | + |
| 109 | + # thx i0 for posting this on the retux Discord |
| 110 | + |
| 111 | + if _logging is True: |
| 112 | + _logging = logging.DEBUG |
| 113 | + |
| 114 | + _format = ( |
| 115 | + "%(asctime)s [%(levelname)s] - .%(funcName)s(): %(message)s" |
| 116 | + if _logging == logging.DEBUG |
| 117 | + else "%(asctime)s [%(levelname)s] - %(message)s" |
| 118 | + ) |
| 119 | + |
| 120 | + logging.basicConfig(format=_format, level=_logging) |
| 121 | + |
105 | 122 | if kwargs.get("disable_sync"): |
106 | 123 | self._automate_sync = False |
107 | 124 | log.warning( |
|
0 commit comments