python str find,python stdout stderr 一起輸出_Python日志記錄在stdout和stderr之間拆分

 2023-11-30 阅读 23 评论 0

摘要:Is it possible to have python logging messages which are INFO or DEBUG to go to stdout and WARNING or greater to go to stderr?解決方案python str find,This seems to do what I want:#!/usr/bin/pythonimport syspython中的數組。import loggingclass InfoFilter(l

Is it possible to have python logging messages which are INFO or DEBUG to go to stdout and WARNING or greater to go to stderr?

解決方案

python str find,This seems to do what I want:

#!/usr/bin/python

import sys

python中的數組。import logging

class InfoFilter(logging.Filter):

def filter(self, rec):

python contains,return rec.levelno in (logging.DEBUG, logging.INFO)

logger = logging.getLogger("__name__")

logger.setLevel(logging.DEBUG)

h1 = logging.StreamHandler(sys.stdout)

h1.setLevel(logging.DEBUG)

h1.addFilter(InfoFilter())

h2 = logging.StreamHandler()

h2.setLevel(logging.WARNING)

logger.addHandler(h1)

logger.addHandler(h2)

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/5/186795.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息