Skip to content

Commit

Permalink
feat: add console handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
ooliver1 committed Oct 3, 2022
1 parent 515edf7 commit 2aff21b
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions botbase/botbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from asyncio import sleep, wait_for
from contextlib import suppress
from importlib import import_module
from logging import CRITICAL, INFO, Formatter, getLogger
from logging import CRITICAL, INFO, Formatter, getLogger, StreamHandler
from logging.handlers import RotatingFileHandler
from pathlib import Path
from random import choice
Expand Down Expand Up @@ -81,21 +81,23 @@
"""


def get_handler():
def get_handlers():
formatter = Formatter(
"%(levelname)-7s %(asctime)s %(filename)12s:%(funcName)-28s: %(message)s",
datefmt="%H:%M:%S %d/%m/%Y",
)
h = RotatingFileHandler(
"./logs/bot/io.log",
maxBytes=1000000,
backupCount=5,
encoding="utf-8",
)
h.setFormatter(
Formatter(
"%(levelname)-7s %(asctime)s %(filename)12s:%(funcName)-28s: %(message)s",
datefmt="%H:%M:%S %d/%m/%Y",
)
)
i = StreamHandler()

i.setFormatter(formatter)
h.setFormatter(formatter)
h.namer = lambda name: name.replace(".log", "") + ".log"
return h
return h, i


class BotBase(AutoShardedBot):
Expand Down Expand Up @@ -147,9 +149,10 @@ def __init__(self, *args, config_module: str = "config", **kwargs) -> None:
log = getLogger()
log.handlers = []
log.setLevel(INFO)
h = get_handler()
h, i = get_handlers()

log.addHandler(h)
log.addHandler(i)
getLogger("asyncio").setLevel(CRITICAL)

self.loop.set_exception_handler(self.asyncio_handler)
Expand Down

0 comments on commit 2aff21b

Please sign in to comment.