fixed logging
This commit is contained in:
47
src/main.py
47
src/main.py
@@ -3,7 +3,7 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
from discord import Intents, Message, RawReactionActionEvent
|
||||
from discord import Intents, Message
|
||||
from dotenv import load_dotenv
|
||||
from rich.highlighter import NullHighlighter
|
||||
from rich.logging import RichHandler
|
||||
@@ -11,43 +11,40 @@ from rich.logging import RichHandler
|
||||
from kwaylon import Kwaylon
|
||||
|
||||
if __name__ == '__main__':
|
||||
rich_handler = RichHandler(
|
||||
highlighter=NullHighlighter(),
|
||||
markup=True,
|
||||
rich_tracebacks=True,
|
||||
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)
|
||||
|
||||
logging.basicConfig(
|
||||
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(),
|
||||
markup=True,
|
||||
rich_tracebacks=True,
|
||||
tracebacks_suppress=['pandas'],
|
||||
)
|
||||
]
|
||||
format=log_format,
|
||||
datefmt=dt_fmt,
|
||||
handlers=[rich_handler]
|
||||
)
|
||||
|
||||
for handler in logging.getLogger('discord.client').handlers:
|
||||
print(handler)
|
||||
|
||||
intents = Intents.default()
|
||||
intents.message_content = True
|
||||
client = Kwaylon(intents=intents)
|
||||
|
||||
@client.event
|
||||
async def on_ready():
|
||||
await client.handle_ready()
|
||||
await client.initialize()
|
||||
|
||||
@client.event
|
||||
async def on_message(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()
|
||||
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