Пример #1
0
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
# -*- Mode: python -*-

import logging
import sys

from thirdparty.ansistrm import ColorizingStreamHandler

for handler in logging.root.handlers[:]:
    logging.root.removeHandler(handler)

logging.addLevelName(logging.ERROR, 'ERROR')
logging.addLevelName(logging.WARNING, 'WARNING')
logging.addLevelName(logging.CRITICAL, 'CRITICAL')
logging.addLevelName(logging.INFO, 'INFO')
logging.addLevelName(logging.DEBUG, 'DEBUG')

logger = logging.getLogger()
#logger_handler = logging.StreamHandler(sys.stdout)
logger_handler = ColorizingStreamHandler(sys.stdout)
formatter = logging.Formatter('[%(asctime)s] [%(levelname)s] %(message)s', '%H:%M:%S')
logger_handler.setFormatter(formatter)
logger.addHandler(logger_handler)
logger.setLevel(logging.WARN)
Пример #2
0
import logging
import sys

LOGGER = logging.getLogger('passzm')

LOGGER_HANDLER = None
try:
		from thirdparty.ansistrm import ColorizingStreamHandler

		disableColor = False

		if disableColor:
				LOGGER_HANDLER = logging.StreamHandler(sys.stdout)
		else:
				LOGGER_HANDLER = ColorizingStreamHandler(sys.stdout)
except ImportError:
		LOGGER_HANDLER = logging.StreamHandler(sys.stdout)

FORMATTER = logging.Formatter("\r[%(asctime)s] [%(levelname)s] %(message)s", "%H:%M:%S")

LOGGER_HANDLER.setFormatter(FORMATTER)
LOGGER.addHandler(LOGGER_HANDLER)
LOGGER.setLevel(logging.INFO)
Пример #3
0
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
# -*- Mode: python -*-

import logging
import sys

from thirdparty.ansistrm import ColorizingStreamHandler

for handler in logging.root.handlers[:]:
    logging.root.removeHandler(handler)

logging.addLevelName(logging.ERROR, 'ERROR')
logging.addLevelName(logging.WARNING, 'WARNING')
logging.addLevelName(logging.CRITICAL, 'CRITICAL')
logging.addLevelName(logging.INFO, 'INFO')
logging.addLevelName(logging.DEBUG, 'DEBUG')

logger = logging.getLogger()
# logger_handler = logging.StreamHandler(sys.stdout)
logger_handler = ColorizingStreamHandler(sys.stdout)
formatter = logging.Formatter('[%(asctime)s] [%(levelname)s] %(message)s',
                              '%H:%M:%S')
logger_handler.setFormatter(formatter)
logger.addHandler(logger_handler)
logger.setLevel(logging.WARN)
Пример #4
0
cmd_hd.setLevel(logging.INFO)

#  修改输出器cmd_hd内部的日志彩色序列,cmd_hd是依据该序列进行彩色输出
cmd_hd.level_map[logging.getLevelName("INFO")] = (None, "cyan", False)
cmd_hd.level_map[logging.getLevelName("SUCCESS")] = (None, "green", False)
cmd_hd.level_map[logging.getLevelName("WARNING")] = (None, "yellow", False)
cmd_hd.level_map[logging.getLevelName("ERROR")] = (None, "red", False)

# 获取格式化程序:common_fmt、debug_fmt,
common_fmt = logging.Formatter(fmt="[%(asctime)s] [%(levelname)s] %(message)s",
                               datefmt="%H:%M:%S")
debug_fmt = logging.Formatter(
    fmt="[%(asctime)s] [%(levelname)s] [%(filename)s] %(message)s",
    datefmt="%Y-%m-%d %H:%M:%S")

# 给输出器 设置 格式化程序
cmd_hd.setFormatter(common_fmt)
file_hd.setFormatter(debug_fmt)

# 给记录器 设置 输出器
LOGGER.addHandler(cmd_hd)
LOGGER.addHandler(file_hd)


def DEBUG():  # 开启调试模式
    # 重新设置输出的日志级别和日志格式
    LOGGER.removeHandler(cmd_hd)
    cmd_hd.setLevel(CUSTOM_LOGGING.INFO)
    cmd_hd.setFormatter(debug_fmt)
    LOGGER.addHandler(cmd_hd)