From 0be6ed0631e9274356a39a09ba0a164a9fc755ed Mon Sep 17 00:00:00 2001 From: Vladless Date: Fri, 15 Nov 2024 23:15:19 +0300 Subject: [PATCH] fix logging --- bot.py | 2 +- handlers/instructions/instructions.py | 27 ++++++++++----------------- middlewares/logging.py | 10 +++++----- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/bot.py b/bot.py index da7ece90..63264af4 100644 --- a/bot.py +++ b/bot.py @@ -12,9 +12,9 @@ router = Router() from handlers import commands, coupons, donate, notifications, pay, profile, start from handlers.admin import admin_commands, admin_coupons, admin_panel, admin_user_editor +from handlers.instructions import instructions from handlers.keys import key_management, keys from handlers.payments import cryprobot_pay, freekassa_pay, robokassa_pay, stars_pay, yookassa_pay -from handlers.instructions import instructions dp.include_router(admin_commands.router) dp.include_router(admin_coupons.router) diff --git a/handlers/instructions/instructions.py b/handlers/instructions/instructions.py index 565ff265..f67fc887 100644 --- a/handlers/instructions/instructions.py +++ b/handlers/instructions/instructions.py @@ -1,16 +1,16 @@ import os -from aiogram import types -from aiogram.types import BufferedInputFile, InlineKeyboardButton, InlineKeyboardMarkup - -from handlers.texts import INSTRUCTIONS -from bot import bot from aiogram import F, Router, types -from config import SUPPORT_CHAT_URL, CONNECT_WINDOWS +from aiogram.types import BufferedInputFile, InlineKeyboardButton, InlineKeyboardMarkup from loguru import logger -from handlers.texts import KEY_MESSAGE, INSTRUCTION_PC + +from bot import bot +from config import CONNECT_WINDOWS, SUPPORT_CHAT_URL +from handlers.texts import INSTRUCTION_PC, INSTRUCTIONS, KEY_MESSAGE router = Router() + + async def send_instructions(callback_query: types.CallbackQuery): await callback_query.message.delete() @@ -67,18 +67,11 @@ async def process_connect_pc(callback_query: types.CallbackQuery): text="🔙 Назад в профиль", callback_data="view_profile" ) - inline_keyboard = [ - [connect_windows_button], - [support_button], - [back_button] - ] + inline_keyboard = [[connect_windows_button], [support_button], [back_button]] keyboard = types.InlineKeyboardMarkup(inline_keyboard=inline_keyboard) await bot.send_message( - tg_id, - instruction_message, - reply_markup=keyboard, - parse_mode="HTML" + tg_id, instruction_message, reply_markup=keyboard, parse_mode="HTML" ) - await callback_query.answer() \ No newline at end of file + await callback_query.answer() diff --git a/middlewares/logging.py b/middlewares/logging.py index 845bfffd..22c57362 100644 --- a/middlewares/logging.py +++ b/middlewares/logging.py @@ -38,11 +38,11 @@ class LoggingMiddleware(BaseMiddleware): class InterceptHandler(logging.Handler): def emit(self, record): - level = ( - logger.level(record.levelname).name - if logger.level(record.levelname) - else record.levelno - ) + try: + level = logger.level(record.levelname).name + except ValueError: + level = "INFO" + logger.log(level, record.getMessage())