aboutsummaryrefslogtreecommitdiff
path: root/voctogui/lib/loghandler.py
blob: 4e48c7d8b2994fbc09f17a32a01998ec2790d535 (plain)
  1. #!/usr/bin/python3
  2. import logging
  3. class LogFormatter(logging.Formatter):
  4. def __init__(self, docolor):
  5. super().__init__()
  6. self.docolor = docolor
  7. def formatMessage(self, record):
  8. if self.docolor:
  9. c_lvl = 33
  10. c_mod = 32
  11. c_msg = 0
  12. if record.levelno == logging.WARNING:
  13. c_lvl = 31
  14. #c_mod = 33
  15. c_msg = 33
  16. elif record.levelno > logging.WARNING:
  17. c_lvl = 31
  18. c_mod = 31
  19. c_msg = 31
  20. fmt = '\x1b['+str(c_lvl)+'m%(levelname)8s\x1b[0m \x1b['+str(c_mod)+'m%(name)s\x1b['+str(c_msg)+'m: %(message)s\x1b[0m'
  21. else:
  22. fmt = '%(levelname)8s %(name)s: %(message)s'
  23. return fmt % record.__dict__
  24. class LogHandler(logging.StreamHandler):
  25. def __init__(self, docolor):
  26. super().__init__()
  27. self.setFormatter(LogFormatter(docolor))