【发布时间】:2016-12-15 00:00:10
【问题描述】:
如何将 elasticsearch 库的日志记录级别设置为与我自己的日志记录不同?为了说明这个问题,我描述了模块场景。我有一个模块lookup.py,它使用elasticsearch,如下所示:
import logging
logger = logging.getLogger(__name__)
import elasticsearch
def get_docs():
logger.debug("search elastic")
es = elasticsearch.Elasticsearch('http://my-es-server:9200/')
res = es.search(index='myindex', body='myquery')
logger.debug("elastic returns %s hits" % res['hits']['total'])
.
.
.
然后在我的主文件中做
import logging
import lookup.py
logging.root.setLevel(loglevel(args))
get_docs()
.
.
.
我从 Elasticsearch 对象内部收到很多调试消息。如何在不抑制 lookup.py 本身的调试消息的情况下使用 lookup.py 中的一些代码抑制它们? Elasticsearch 类似乎有一个 logger 对象;我尝试将其设置为None,但这并没有改变任何东西。
【问题讨论】: