broke out the logging config
This commit is contained in:
@@ -3,13 +3,37 @@ import logging
|
||||
import os
|
||||
|
||||
from dotenv import load_dotenv
|
||||
from rich.console import Console
|
||||
from rich.highlighter import NullHighlighter
|
||||
from rich.logging import RichHandler
|
||||
|
||||
from .jokes import GifJoke, Joke
|
||||
from .kwaylon import Kwaylon
|
||||
from .reactions import ReactionData
|
||||
|
||||
|
||||
def init_logging(log_level: int = logging.INFO):
|
||||
rich_handler = RichHandler(
|
||||
console=Console(width=150),
|
||||
highlighter=NullHighlighter(),
|
||||
markup=True,
|
||||
rich_tracebacks=True,
|
||||
tracebacks_suppress=['pandas', 'discord'],
|
||||
)
|
||||
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'
|
||||
|
||||
logging.basicConfig(
|
||||
level=log_level,
|
||||
format=log_format,
|
||||
datefmt=dt_fmt,
|
||||
handlers=[rich_handler]
|
||||
)
|
||||
|
||||
|
||||
def main(token_var: str = 'DISCORD_TOKEN'):
|
||||
init_logging(logging.DEBUG)
|
||||
load_dotenv()
|
||||
loop = asyncio.new_event_loop()
|
||||
loop.create_task(
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
from typing import AsyncIterator, List
|
||||
@@ -10,9 +7,6 @@ import pandas as pd
|
||||
from discord import (Client, Emoji, Guild, Intents, Message,
|
||||
RawReactionActionEvent, TextChannel, utils)
|
||||
from dotenv import load_dotenv
|
||||
from rich.console import Console
|
||||
from rich.highlighter import NullHighlighter
|
||||
from rich.logging import RichHandler
|
||||
|
||||
from . import jokes
|
||||
|
||||
@@ -47,25 +41,6 @@ class Kwaylon(Client):
|
||||
|
||||
@classmethod
|
||||
async def create_and_start(cls, token: str, log_level: int = logging.INFO):
|
||||
rich_handler = RichHandler(
|
||||
console=Console(width=150),
|
||||
highlighter=NullHighlighter(),
|
||||
markup=True,
|
||||
rich_tracebacks=True,
|
||||
tracebacks_suppress=['pandas', 'discord'],
|
||||
)
|
||||
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=log_level,
|
||||
format=log_format,
|
||||
datefmt=dt_fmt,
|
||||
handlers=[rich_handler]
|
||||
)
|
||||
|
||||
intents = Intents.default()
|
||||
intents.message_content = True
|
||||
client = cls(intents=intents)
|
||||
|
||||
Reference in New Issue
Block a user