feat: allow Log.error to pass exception

This commit is contained in:
relikd
2023-03-19 13:51:23 +01:00
parent 24aa71c8bc
commit 4f160cefcd
2 changed files with 8 additions and 4 deletions

View File

@@ -2,6 +2,7 @@
import re
import os # utime, getmtime
import time # mktime, time
import traceback # format_exc
from sys import stderr
from html import unescape
from datetime import datetime
@@ -22,11 +23,14 @@ class Log:
fp.write(msg + '\n')
@staticmethod
def error(e: str) -> None:
def error(e: Union[str, Exception]) -> None:
''' Log error message (incl. current timestamp) '''
msg = '{} [ERROR] {}'.format(datetime.now(), e)
msg = '{} [ERROR] {}'.format(
datetime.now(), e if isinstance(e, str) else repr(e))
print(msg, file=stderr)
Log._log_if(0, msg)
if isinstance(e, Exception):
Log._log_if(0, traceback.format_exc())
@staticmethod
def info(m: str) -> None:

View File

@@ -42,7 +42,7 @@ class TGClient(telebot.TeleBot):
self.onKillCallback()
return
except Exception as e:
Log.error(repr(e))
Log.error(e)
Log.info('Auto-restart in 15 sec ...')
sleep(15)
_fn()
@@ -91,7 +91,7 @@ class TGClient(telebot.TeleBot):
try:
return self.send_message(chat_id, msg, **kwargs)
except Exception as e:
Log.error(repr(e))
Log.error(e)
sleep(45)
return None