log_service.py 466 B

12345678910111213141516171819202122
  1. import functools
  2. import logging
  3. import traceback
  4. logger = logging.getLogger('django')
  5. def auto_log(func):
  6. """
  7. auto write log decorator
  8. :param func:
  9. :return:
  10. """
  11. @functools.wraps(func)
  12. def _deco(*args, **kwargs):
  13. try:
  14. real_func = func(*args, **kwargs)
  15. return real_func
  16. except Exception as e:
  17. logger.error(traceback.format_exc())
  18. return False, e.__str__()
  19. return _deco