本文整理汇总了Python中rainbow_logging_handler.RainbowLoggingHandler.setFormatter方法的典型用法代码示例。如果您正苦于以下问题:Python RainbowLoggingHandler.setFormatter方法的具体用法?Python RainbowLoggingHandler.setFormatter怎么用?Python RainbowLoggingHandler.setFormatter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rainbow_logging_handler.RainbowLoggingHandler
的用法示例。
在下文中一共展示了RainbowLoggingHandler.setFormatter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_logging
# 需要导入模块: from rainbow_logging_handler import RainbowLoggingHandler [as 别名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 别名]
def setup_logging() -> None:
"""
Sets up the logging module to have a verbose option and formats the Console handler and File handler
"""
logging.addLevelName(VERBOSE, "VERBOSE")
logging.Logger.verbose = logger_verbose
logging.verbose = logging_verbose
logging.VERBOSE = VERBOSE
# define console handler
console_handler = ConsoleHandler(sys.stderr)
if hasattr(console_handler, "_column_color"):
# noinspection PyProtectedMember
# pylint: disable=protected-access
console_handler._column_color['%(message)s'][logging.VERBOSE] = ('cyan', None, False)
console_formatter = logging.Formatter("[%(asctime)s] %(levelname)s : %(message)s", "%H:%M:%S")
console_handler.setFormatter(console_formatter)
console_handler.setLevel(logging.VERBOSE)
# define file handler
if not os.path.exists(os.path.dirname(get_global_conf().getdir("install", "log_file"))):
os.makedirs(os.path.dirname(get_global_conf().getdir("install", "log_file")))
file_handler = logging.FileHandler(get_global_conf().getdir("install", "log_file"))
# add handlers
logging.getLogger().addHandler(console_handler)
logging.getLogger().addHandler(file_handler)
logging.getLogger().setLevel(get_global_conf().getint("install", "log_level"))
示例2: setup_console_logging
# 需要导入模块: from rainbow_logging_handler import RainbowLoggingHandler [as 别名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 别名]
def setup_console_logging(log_level=None):
"""Setup console logging.
Aimed to give easy sane defaults for loggig in command line applications.
Don't use logging settings from INI, but use hardcoded defaults.
"""
formatter = logging.Formatter("[%(asctime)s] [%(name)s %(funcName)s] %(message)s") # same as default
# setup `RainbowLoggingHandler`
# and quiet some logs for the test output
handler = RainbowLoggingHandler(sys.stdout)
handler.setFormatter(formatter)
logger = logging.getLogger()
logger.handlers = [handler]
env_level = os.environ.get("LOG_LEVEL", "info")
log_level = log_level or getattr(logging, env_level.upper())
logger.setLevel(log_level)
logger = logging.getLogger("requests.packages.urllib3.connectionpool")
logger.setLevel(logging.ERROR)
# SQL Alchemy transactions
logger = logging.getLogger("txn")
logger.setLevel(logging.ERROR)
示例3: setup
# 需要导入模块: from rainbow_logging_handler import RainbowLoggingHandler [as 别名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 别名]
def setup():
formatter = logging.Formatter("[%(asctime)s] %(name)s %(funcName)s():%(lineno)d\t%(message)s") # same as default
# setup `RainbowLoggingHandler`
# and quiet some logs for the test output
handler = RainbowLoggingHandler(sys.stderr)
handler.setFormatter(formatter)
logger = logging.getLogger()
logger.addHandler(handler)
if "VERBOSE_TEST" in os.environ:
logger.setLevel(logging.DEBUG)
else:
logger.setLevel(logging.ERROR)
logger = logging.getLogger("requests.packages.urllib3.connectionpool")
logger.setLevel(logging.ERROR)
logger = logging.getLogger("cryptoassets.core.backend.blockio")
logger.setLevel(logging.DEBUG)
logger = logging.getLogger("cryptoassets.core.backend.bitcoind")
logger.setLevel(logging.WARN)
# SQL Alchemy transactions
logger = logging.getLogger("txn")
logger.setLevel(logging.ERROR)
示例4: setup_custom_logger
# 需要导入模块: from rainbow_logging_handler import RainbowLoggingHandler [as 别名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 别名]
def setup_custom_logger():
LOG_FILE = 'log/cpa'
formatter = logging.Formatter("[%(asctime)s] %(threadName)s - %(pathname)s %(funcName)s():%(lineno)d %(levelname)s \t%(message)s") # same as default
# formatter = logging.Formatter('%(asctime)s [%(pathname)s: %(lineno)d] %(levelname)s %(message)s')
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
file_handler = ParallelTimedRotatingFileHandler(LOG_FILE, when='H')
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
# console_handler = logging.StreamHandler(sys.stdout)
# console_handler.formatter = formatter
# logger.addHandler(console_handler)
# setup `RainbowLoggingHandler`
handler = RainbowLoggingHandler(sys.stderr, color_funcName=('black', 'yellow', True))
handler.setFormatter(formatter)
logger.addHandler(handler)
#Add file handler
handler = TimedRotatingFileHandler(LOG_FILE,
when="h",
interval=1,
backupCount=48)
# try:
# raise RuntimeError("Opa!")
# except Exception as e:
# logger.exception(e)
return logger
示例5: test_format_all_column
# 需要导入模块: from rainbow_logging_handler import RainbowLoggingHandler [as 别名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 别名]
def test_format_all_column():
logger = logging.getLogger('test_logging_format_all_column')
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('''
name = '%(name)s'
levelno = '%(levelno)s'
levelname = '%(levelname)s'
pathname = '%(pathname)s'
filename = '%(filename)s'
module = '%(module)s'
lineno = '%(lineno)d'
funcName = '%(funcName)s'
created = '%(created)f'
asctime = '%(asctime)s'
msecs = '%(msecs)d'
relativeCreated = '%(relativeCreated)d'
thread = '%(thread)d'
threadName = '%(threadName)s'
process = '%(process)d'
message = '%(message)s'
''')
handler = RainbowLoggingHandler(sys.stderr)
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.debug("debug msg")
示例6: setup_logging
# 需要导入模块: from rainbow_logging_handler import RainbowLoggingHandler [as 别名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 别名]
def setup_logging():
log = logging.getLogger("")
handler = RainbowLoggingHandler(sys.stderr)
handler._column_color['%(asctime)s'] = ('cyan', None, False)
handler._column_color['%(levelname)-7s'] = ('green', None, False)
handler._column_color['%(message)s'][logging.INFO] = ('blue', None, False)
handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)-7s %(name)-15s %(message)s"))
log.addHandler(handler)
log.setLevel(logging.INFO)
示例7: logger
# 需要导入模块: from rainbow_logging_handler import RainbowLoggingHandler [as 别名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 别名]
def logger(config_file):
CONFIG = configparser.RawConfigParser()
CONFIG.read(config_file)
logger_config = CONFIG['logger']
logger = logging.getLogger(logger_config['name'])
logger.setLevel(LOGGING_LEVELS.get(logger_config['level'], logging.NOTSET))
formatter = logging.Formatter(
'[%(asctime)s] %(name)s %(funcName)s():%(lineno)d\t%(message)s'
)
handler = RainbowLoggingHandler(
sys.stderr,
color_funcName=('black', 'yellow', True)
)
handler.setFormatter(formatter)
logger.addHandler(handler)
if CONFIG.has_section('file_logger'):
file_logger_config = CONFIG['file_logger']
fh = logging.handlers.RotatingFileHandler(
file_logger_config['file_path'],
maxBytes=int(file_logger_config['max_log_file_size']),
backupCount=int(file_logger_config['backup_count'])
)
fh.setLevel(LOGGING_LEVELS.get(file_logger_config['level'],
logging.NOTSET))
fh.setFormatter(formatter)
logger.addHandler(fh)
if CONFIG.has_section('email_logger'):
email_logger_config = CONFIG['email_logger']
eh = logging.handlers.SMTPHandler(
(email_logger_config['host'], email_logger_config['port']),
email_logger_config['from'],
email_logger_config['to'],
email_logger_config['subject'],
(email_logger_config['username'], email_logger_config['password']),
()
)
eh.setLevel(LOGGING_LEVELS.get(email_logger_config['level'],
logging.NOTSET))
eh.setFormatter(formatter)
logger.addHandler(eh)
return logger
示例8: add_stdout_handler
# 需要导入模块: from rainbow_logging_handler import RainbowLoggingHandler [as 别名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 别名]
def add_stdout_handler(logger, formatter):
try:
from rainbow_logging_handler import RainbowLoggingHandler
handler = RainbowLoggingHandler(sys.stderr, color_funcName=(
'black', 'black', True))
except ImportError:
handler = logging.StreamHandler()
pass
handler.setFormatter(formatter)
logger.addHandler(handler)
示例9: setup_logging
# 需要导入模块: from rainbow_logging_handler import RainbowLoggingHandler [as 别名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 别名]
def setup_logging(verbose=False):
log = logging.getLogger("")
handler = RainbowLoggingHandler(sys.stderr)
handler._column_color['%(asctime)s'] = ('cyan', None, False)
handler._column_color['%(levelname)-7s'] = ('green', None, False)
handler._column_color['%(message)s'][logging.INFO] = ('blue', None, False)
handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)-7s %(name)-15s %(message)s"))
log.addHandler(handler)
log.setLevel([logging.INFO, logging.DEBUG][verbose])
logging.getLogger("boto").level = logging.CRITICAL
示例10: test_custom_format
# 需要导入模块: from rainbow_logging_handler import RainbowLoggingHandler [as 别名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 别名]
def test_custom_format():
logger = logging.getLogger('test_logging_custom_format')
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter("MESSAGE ONLY => %(message)s")
handler = RainbowLoggingHandler(sys.stderr)
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.debug("debug msg")
logger.info("info msg")
logger.warn("warn msg")
logger.error("error msg")
logger.critical("critical msg")
示例11: setup_logging
# 需要导入模块: from rainbow_logging_handler import RainbowLoggingHandler [as 别名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 别名]
def setup_logging(verbose=False, silent=False, debug=False):
log = logging.getLogger("")
handler = RainbowLoggingHandler(sys.stderr)
handler._column_color['%(asctime)s'] = ('cyan', None, False)
handler._column_color['%(levelname)-7s'] = ('green', None, False)
handler._column_color['%(message)s'][logging.INFO] = ('blue', None, False)
handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)-7s %(name)-15s %(message)s"))
log.addHandler(handler)
log.setLevel([logging.INFO, logging.DEBUG][verbose or debug])
if silent:
log.setLevel(logging.ERROR)
logging.getLogger("requests").setLevel([logging.CRITICAL, logging.ERROR][verbose or debug])
return handler
示例12: setup
# 需要导入模块: from rainbow_logging_handler import RainbowLoggingHandler [as 别名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 别名]
def setup():
# prepare log file
global f_log, logpath
(fd, logpath) = mkstemp(prefix='raibow-', suffix='.txt')
f_log = os.fdopen(fd, 'w')
# prepare 'test_format' logger
logger = logging.getLogger('test_format')
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter("AAA %(name)s - %(levelname)s - %(message)s ZZZ") # testing whether this format is used
handler = RainbowLoggingHandler(f_log)
handler.setFormatter(formatter)
logger.addHandler(handler)
示例13: get_logger
# 需要导入模块: from rainbow_logging_handler import RainbowLoggingHandler [as 别名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 别名]
def get_logger():
global logger
if logger == None:
logger = logging.getLogger('freesprints')
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter("[%(asctime)s] %(name)s %(funcName)s():%(lineno)d\t%(message)s") # same as default
# setup colored logging
handler = RainbowLoggingHandler(sys.stderr, color_funcName=('black', 'yellow', True))
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger
示例14: __init__
# 需要导入模块: from rainbow_logging_handler import RainbowLoggingHandler [as 别名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 别名]
def __init__(self, module_name):
self.logger_tmp = None
logger = logging.getLogger(module_name)
logging.basicConfig(filename='/tmp/r2als.log',level=logging.DEBUG,format='%(asctime)s %(levelname)s %(message)s')
# logging.basicConfig(level=logging.DEBUG)
formatter = logging.Formatter("[%(asctime)s] %(name)s %(funcName)s():%(lineno)d\t%(message)s") # same as default
# setup `RainbowLoggingHandler`
handler = RainbowLoggingHandler(sys.stderr, color_funcName=('black', 'gray', True))
handler.setFormatter(formatter)
logger.addHandler(handler)
self.logger_tmp = logger
示例15: setup_logging
# 需要导入模块: from rainbow_logging_handler import RainbowLoggingHandler [as 别名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import setFormatter [as 别名]
def setup_logging(self, args, verbose=False, silent=False, debug=False, logging_name=""):
"""Setup the RainbowLoggingHandler for the logs and call setup_other_logging"""
log = logging.getLogger(logging_name)
handler = RainbowLoggingHandler(self.logging_handler_file)
handler._column_color['%(asctime)s'] = ('cyan', None, False)
handler._column_color['%(levelname)-7s'] = ('green', None, False)
handler._column_color['%(message)s'][logging.INFO] = ('blue', None, False)
handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)-7s %(name)-15s %(message)s"))
log.addHandler(handler)
log.setLevel([logging.INFO, logging.DEBUG][verbose or debug])
if silent:
log.setLevel(logging.ERROR)
self.setup_other_logging(args, verbose, silent, debug)
return handler