本文整理匯總了Python中rainbow_logging_handler.RainbowLoggingHandler.addFilter方法的典型用法代碼示例。如果您正苦於以下問題:Python RainbowLoggingHandler.addFilter方法的具體用法?Python RainbowLoggingHandler.addFilter怎麽用?Python RainbowLoggingHandler.addFilter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rainbow_logging_handler.RainbowLoggingHandler
的用法示例。
在下文中一共展示了RainbowLoggingHandler.addFilter方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: enable_logging
# 需要導入模塊: from rainbow_logging_handler import RainbowLoggingHandler [as 別名]
# 或者: from rainbow_logging_handler.RainbowLoggingHandler import addFilter [as 別名]
def enable_logging(filename: str, level: str):
class Squelch(logging.Filter):
def filter(self, record):
if record.levelno == logging.DEBUG:
return not record.name.startswith('asyncio') and \
not record.name.startswith('websockets') and \
not record.name.startswith('aiohttp')
elif record.levelno == logging.INFO and record.name.startswith('asyncio'):
return False
return True
formatter = logging.Formatter(fmt='%(asctime)s.%(msecs)03d:%(levelname)s:%(name)s:%(message)s')
# File logger captures everything.
file_handler = logging.FileHandler(filename)
file_handler.setLevel(logging.DEBUG)
# Console output level is configurable.
stream_handler = RainbowLoggingHandler(
sys.stdout,
color_asctime=('cyan', None, False),
color_msecs=('cyan', None, False),
color_levelname=('gray', None, False),
color_module=('yellow', None, False),
color_name=('blue', None, False),
color_lineno=('green', None, False),
datefmt="%Y-%m-%d %H:%M:%S"
)
stream_handler.setLevel(getattr(logging, level))
stream_handler.addFilter(Squelch())
# Set an output format.
stream_handler.setFormatter(formatter)
file_handler.setFormatter(formatter)
file_handler.addFilter(Squelch())
# Add handlers to root.
root = logging.getLogger('')
root.setLevel(logging.DEBUG)
root.addHandler(stream_handler)
root.addHandler(file_handler)