_logging.py 910 B

123456789101112131415161718192021222324252627282930313233
  1. import sys,logging
  2. #from loguru import logger
  3. def __exception_handle(e_type, e_value, e_traceback):
  4. if issubclass(e_type, KeyboardInterrupt):
  5. print('\nBye...')
  6. sys.exit(0)
  7. sys.__excepthook__(e_type, e_value, e_traceback)
  8. #class __InterceptHandler(logging.Handler):
  9. # def emit(self, record):
  10. # try:
  11. # level = logger.level(record.levelname).name
  12. # except ValueError:
  13. # level = record.levelno
  14. #
  15. # frame, depth = logging.currentframe(), 2
  16. # while frame.f_code.co_filename == logging.__file__:
  17. # frame = frame.f_back
  18. # depth += 1
  19. # logger.opt(depth=depth, exception=record.exc_info).log(
  20. # level, record.getMessage()
  21. # )
  22. def hook_except_handle():
  23. sys.excepthook = __exception_handle
  24. #def hook_logging(**kwargs):
  25. # logging.basicConfig(handlers=[__InterceptHandler()], **kwargs)