fix: base thread添加日志
This commit is contained in:
parent
24b2a98440
commit
b9f2264ff4
|
@ -1,23 +1,9 @@
|
|||
import threading
|
||||
import logging
|
||||
from apps.utils.tasks import send_mail_task
|
||||
import traceback
|
||||
|
||||
logger = logging.getLogger('log')
|
||||
from apps.utils.decorators import auto_log
|
||||
|
||||
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):
|
||||
try:
|
||||
if self._target:
|
||||
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
|
||||
@auto_log('MyThread', raise_exception=True, send_mail=True)
|
||||
def run(self) -> None:
|
||||
return super().run()
|
||||
|
Loading…
Reference in New Issue