fix: base thread添加日志
This commit is contained in:
parent
24b2a98440
commit
b9f2264ff4
|
@ -1,23 +1,9 @@
|
||||||
import threading
|
import threading
|
||||||
import logging
|
from apps.utils.decorators import auto_log
|
||||||
from apps.utils.tasks import send_mail_task
|
|
||||||
import traceback
|
|
||||||
|
|
||||||
logger = logging.getLogger('log')
|
|
||||||
|
|
||||||
class MyThread(threading.Thread):
|
class MyThread(threading.Thread):
|
||||||
def __init__(self, log_err=False, send_err=False):
|
|
||||||
super().__init__()
|
|
||||||
self.send_err = send_err
|
|
||||||
self.log_err = log_err
|
|
||||||
|
|
||||||
def run(self):
|
@auto_log('MyThread', raise_exception=True, send_mail=True)
|
||||||
try:
|
def run(self) -> None:
|
||||||
if self._target:
|
return super().run()
|
||||||
self._target(*self._args, **self._kwargs)
|
|
||||||
except Exception as e:
|
|
||||||
if self.log_err:
|
|
||||||
logger.error(f"Thread error: {e}", exc_info=False)
|
|
||||||
if self.send_err:
|
|
||||||
send_mail_task.delay(message=traceback.format_exc())
|
|
||||||
raise
|
|
Loading…
Reference in New Issue