首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Python中从第三方模块禁用信息日志记录

如何在Python中从第三方模块禁用信息日志记录
EN

Stack Overflow用户
提问于 2016-01-04 20:05:38
回答 1查看 4K关注 0票数 4

我正在使用Python查询一个Serf集群,但是我想禁止来自Serf的INFO数据。我试图重写它,以便它只打印WARNING消息,但是它拒绝尊重它。

输出:

代码语言:javascript
复制
01-04 14:57 root         INFO     Connecting to cluster
01-04 14:57 serf-rpc-client INFO     will connect to [('myhost.localdomain.local', 7373, {})]
01-04 14:57 serf-rpc-client INFO     trying to connect to myhost.localdomain.local:7373
01-04 14:57 serf-rpc-client INFO     connected to myhost.localdomain.local:7373
01-04 14:57 serf-rpc-client INFO     trying to request command: <RequestHandshake: handshake, 0, {'Version': 1}>
01-04 14:57 serf-rpc-client INFO     trying to request command: <RequestAuth: auth, 1, {'AuthKey': 'thundercats'}>
01-04 14:57 serf-rpc-client INFO     trying to request command: <RequestMembers: members, 2, {'Status': 'failed'}>
01-04 14:57 serf-rpc-client INFO     successfully handshaked
01-04 14:57 serf-rpc-client INFO     successfully authed
01-04 14:57 root         INFO     myhost123.localdomain.local has left the cluster

测井代码

代码语言:javascript
复制
logging.basicConfig(level=logging.INFO,
                format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
                datefmt='%m-%d %H:%M',
                filename='/var/log/ocd_watcher.log',
                filemode='w')

serf_logger = logging.getLogger('serf')
serf_logger.setLevel(logging.WARNING)

console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
console_handler.setFormatter(default_formatter)

logger = logging.getLogger()
logger.addHandler(console_handler)
logger.addHandler(serf_logger)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-04 20:07:40

记录器的名称是serf-rpc-client,所以这应该可以工作。

代码语言:javascript
复制
serf_logger = logging.getLogger('serf-rpc-client')
serf_logger.setLevel(logging.WARNING)
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34598952

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档