fixed logging
This commit is contained in:
41
src/main.py
41
src/main.py
@@ -3,7 +3,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from discord import Intents, Message, RawReactionActionEvent
|
from discord import Intents, Message
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from rich.highlighter import NullHighlighter
|
from rich.highlighter import NullHighlighter
|
||||||
from rich.logging import RichHandler
|
from rich.logging import RichHandler
|
||||||
@@ -11,23 +11,23 @@ from rich.logging import RichHandler
|
|||||||
from kwaylon import Kwaylon
|
from kwaylon import Kwaylon
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
logging.basicConfig(
|
rich_handler = RichHandler(
|
||||||
level=logging.DEBUG,
|
|
||||||
# https://docs.python.org/3/library/logging.html#logrecord-attributes
|
|
||||||
format='[magenta]%(name)s[/] [cyan]%(funcName)s[/] %(message)s',
|
|
||||||
datefmt='%Y-%m-%d %I:%M:%S %p',
|
|
||||||
handlers=[
|
|
||||||
RichHandler(
|
|
||||||
highlighter=NullHighlighter(),
|
highlighter=NullHighlighter(),
|
||||||
markup=True,
|
markup=True,
|
||||||
rich_tracebacks=True,
|
rich_tracebacks=True,
|
||||||
tracebacks_suppress=['pandas'],
|
tracebacks_suppress=['pandas'],
|
||||||
)
|
)
|
||||||
]
|
dt_fmt = '%Y-%m-%d %I:%M:%S %p'
|
||||||
)
|
# https://docs.python.org/3/library/logging.html#logrecord-attributes
|
||||||
|
log_format = '[magenta]%(name)s[/] [cyan]%(funcName)s[/] %(message)s'
|
||||||
|
formatter = logging.Formatter(log_format, dt_fmt)
|
||||||
|
|
||||||
for handler in logging.getLogger('discord.client').handlers:
|
logging.basicConfig(
|
||||||
print(handler)
|
level=logging.DEBUG,
|
||||||
|
format=log_format,
|
||||||
|
datefmt=dt_fmt,
|
||||||
|
handlers=[rich_handler]
|
||||||
|
)
|
||||||
|
|
||||||
intents = Intents.default()
|
intents = Intents.default()
|
||||||
intents.message_content = True
|
intents.message_content = True
|
||||||
@@ -35,19 +35,16 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
await client.handle_ready()
|
await client.initialize()
|
||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
async def on_message(message: Message):
|
async def on_message(message: Message):
|
||||||
await client.handle_message(message)
|
await client.handle_message(message)
|
||||||
|
|
||||||
@client.event
|
|
||||||
async def on_raw_reaction_add(payload: RawReactionActionEvent):
|
|
||||||
await client.handle_raw_reaction(payload)
|
|
||||||
|
|
||||||
@client.event
|
|
||||||
async def on_raw_reaction_remove(payload: RawReactionActionEvent):
|
|
||||||
await client.handle_raw_reaction(payload)
|
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
client.run(os.getenv('DISCORD_TOKEN'))
|
client.run(
|
||||||
|
os.getenv('DISCORD_TOKEN'),
|
||||||
|
log_handler=rich_handler,
|
||||||
|
log_formatter=formatter,
|
||||||
|
log_level=logging.INFO,
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user