diff --git a/TelegramEDT/__init__.py b/TelegramEDT/__init__.py index e54622c..05c904a 100644 --- a/TelegramEDT/__init__.py +++ b/TelegramEDT/__init__.py @@ -13,6 +13,7 @@ from sqlalchemy.orm import sessionmaker from TelegramEDT.EDTcalendar import Calendar from TelegramEDT.base import Base, User from TelegramEDT.lang import lang +from TelegramEDT.logger import logger tables = False if not isdir("logs"): @@ -22,14 +23,6 @@ if not isdir("calendars"): if not isfile("edt.db"): tables = True -logger = logging.getLogger("TelegramEDT") -log_date = datetime.datetime.now(datetime.timezone.utc).astimezone(tz=None).date() -logging.basicConfig( - filename=f"logs/{log_date}.log", - format="{%(levelname)s}[%(asctime)s]: %(name)s | %(message)s", - level=logging.INFO, -) - if not isfile("token.ini"): logger.critical("No token specified, impossible to start the bot !") exit(1) diff --git a/TelegramEDT/logger.py b/TelegramEDT/logger.py new file mode 100644 index 0000000..3e8dac5 --- /dev/null +++ b/TelegramEDT/logger.py @@ -0,0 +1,15 @@ +import logging +from logging import handlers + +log_format = "{%(levelname)s}[%(asctime)s]: %(name)s | %(message)s" + +logging.basicConfig( + format=log_format, + level=logging.INFO +) +logger = logging.getLogger("TelegramEDT") +handler = handlers.TimedRotatingFileHandler("logs/current.log", when="d", interval=1) +handler.suffix = "%Y-%m-%d" +handler.style = log_format +handler.setFormatter(logging.Formatter(log_format)) +logger.addHandler(handler) diff --git a/TelegramEDT/tools.py b/TelegramEDT/tools.py index 74c26ec..34559f4 100644 --- a/TelegramEDT/tools.py +++ b/TelegramEDT/tools.py @@ -1,9 +1,11 @@ +import datetime + from aiogram import types from aiogram.types import ParseMode from aiogram.utils import markdown from aiogram.utils.exceptions import MessageIsTooLong -from TelegramEDT import ADMIN_ID, bot, dbL, dp, key, log_date, logger, session, check_id +from TelegramEDT import ADMIN_ID, bot, dbL, dp, key, logger, session, check_id from TelegramEDT.base import User logger = logger.getChild("tools") @@ -24,11 +26,11 @@ async def get_logs(message: types.Message): int(message.text[9:]) except ValueError: await message.chat.do(types.ChatActions.UPLOAD_DOCUMENT) - await message.reply_document(types.InputFile(f"logs/{log_date}.log"), caption=f"The {log_date} logs", + await message.reply_document(types.InputFile(f"logs/current.log"), caption="The logs file", reply_markup=key) else: await message.chat.do(types.ChatActions.TYPING) - logs = (open(f"logs/{log_date}.log", "r").readlines())[-int(message.text[9:]):] + logs = (open(f"logs/current.log", "r").readlines())[-int(message.text[9:]):] log = str() for i in logs: log += i