Avoid generating 'No handlers could be found for logger "elasticsearch"' errors
by installing no-op logging handler per <https://docs.python.org/2/howto/logging.html#configuring-logging-for-a-library>.
This commit is contained in:
committed by
Honza Král
parent
953c66e650
commit
51c89a8a2b
@@ -4,6 +4,17 @@ VERSION = (1, 2, 0)
|
||||
__version__ = VERSION
|
||||
__versionstr__ = '.'.join(map(str, VERSION))
|
||||
|
||||
import sys
|
||||
|
||||
if (2, 7) <= sys.version_info < (3, 2):
|
||||
# On Python 2.7 and Python3 < 3.2, install no-op handler to silence
|
||||
# `No handlers could be found for logger "elasticsearch"` message per
|
||||
# <https://docs.python.org/2/howto/logging.html#configuring-logging-for-a-library>,
|
||||
# <https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library>:
|
||||
import logging
|
||||
logger = logging.getLogger('elasticsearch')
|
||||
logger.addHandler(logging.NullHandler())
|
||||
|
||||
from .client import Elasticsearch
|
||||
from .transport import Transport
|
||||
from .connection_pool import ConnectionPool, ConnectionSelector, \
|
||||
|
||||
Reference in New Issue
Block a user