You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
698 B

import logging
import traceback
from io import StringIO # Для перевода лога в переменную
import telebot
# Базовая инициализация
global log_stream
log_stream = StringIO()
logging.basicConfig(stream=log_stream)
def catch_error(bot, message, err_type = None):
try:
if not err_type:
global log_stream
logging.error(traceback.format_exc()) # Логирование ошибок
err = log_stream.getvalue() # Ошибка -> переменная
bot.reply_to(message, "Critical error:\n\n" + telebot.formatting.hcode(err), parse_mode='HTML')
# Очистка логов
log_stream.truncate(0)
log_stream.seek(0)
except:
pass