Logging.py 781 B

123456789101112131415161718192021222324252627282930313233343536
  1. # coding=utf-8
  2. """ 日志工具类 """
  3. import sys
  4. class Logging(object):
  5. """ 日志工具 """
  6. RED = '\033[31m'
  7. GREEN = '\033[32m'
  8. YELLOW = '\033[33m'
  9. MAGENTA = '\033[35m'
  10. RESET = '\033[0m'
  11. @staticmethod
  12. def __print(s, color=None):
  13. if color and sys.stdout.isatty() and sys.platform != 'win32':
  14. print color + s + Logging.RESET
  15. else:
  16. print s
  17. @staticmethod
  18. def debug(s):
  19. Logging.__print("Debug: " + s, Logging.MAGENTA)
  20. @staticmethod
  21. def info(s):
  22. Logging.__print("Info: " + s, Logging.GREEN)
  23. @staticmethod
  24. def warning(s):
  25. Logging.__print("Warning: " + s, Logging.YELLOW)
  26. @staticmethod
  27. def error(s):
  28. Logging.__print("Error: " + s, Logging.RED)