From 482f166c1af960aa23da61cb1308d66f40b89ed1 Mon Sep 17 00:00:00 2001 From: j0hnsmith Date: Thu, 4 Dec 2014 11:16:08 +0000 Subject: [PATCH] set propagate=False on elasticsearch.trace only if logger not already configured --- docs/index.rst | 4 ++-- elasticsearch/connection/base.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 92e28474..b11050ef 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -136,8 +136,8 @@ two loggers: ``elasticsearch`` and ``elasticsearch.trace``. ``elasticsearch`` is used by the client to log standard activity, depending on the log level. ``elasticsearch.trace`` can be used to log requests to the server in the form of ``curl`` commands using pretty-printed json that can then be executed from -command line. The trace logger doesn't inherit from the base one - it needs to -be activated separately. +command line. If the trace logger has not been configured already it is set to +`propagate=False` so it needs to be activated separately. .. _logging library: http://docs.python.org/3.3/library/logging.html diff --git a/elasticsearch/connection/base.py b/elasticsearch/connection/base.py index 4995908c..0bc6192f 100644 --- a/elasticsearch/connection/base.py +++ b/elasticsearch/connection/base.py @@ -7,8 +7,13 @@ except ImportError: from ..exceptions import TransportError, HTTP_EXCEPTIONS logger = logging.getLogger('elasticsearch') + +# create the elasticsearch.trace logger, but only set propagate to False if the +# logger hasn't already been configured +_tracer_already_configured = 'elasticsearch.trace' in logging.Logger.manager.loggerDict tracer = logging.getLogger('elasticsearch.trace') -tracer.propagate = False +tracer.propagate = not _tracer_already_configured + class Connection(object): """