一.第三方模块coloredlogs
# Create a logger object. import logging logger = logging.getLogger('your-module') # Initialize coloredlogs. import coloredlogs coloredlogs.install(level='DEBUG') # Some examples. logger.debug("this is a debugging message") logger.info("this is an informational message") logger.warn("this is a warning message") logger.error("this is an error message") logger.critical("this is a critical message")
二.代码实现
示例一
#!/usr/bin/env python # -*- coding: utf-8 -*- class bcolors: HEADER = '