PROTON-1347: Use a dedicated proton logger, not the root one; disable log output by default
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/73aa2d7b Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/73aa2d7b Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/73aa2d7b Branch: refs/heads/go1 Commit: 73aa2d7bdf9f6332d08b7e190aadcdacbebf09ee Parents: 1b1f3f9 Author: Justin Ross <[email protected]> Authored: Tue Aug 15 16:10:11 2017 -0700 Committer: Justin Ross <[email protected]> Committed: Tue Aug 15 16:10:11 2017 -0700 ---------------------------------------------------------------------- proton-c/bindings/python/proton/__init__.py | 15 +++++++++------ proton-c/bindings/python/proton/handlers.py | 9 +++++---- proton-c/bindings/python/proton/reactor.py | 14 ++++++++------ 3 files changed, 22 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/73aa2d7b/proton-c/bindings/python/proton/__init__.py ---------------------------------------------------------------------- diff --git a/proton-c/bindings/python/proton/__init__.py b/proton-c/bindings/python/proton/__init__.py index dca600b..43f4067 100644 --- a/proton-c/bindings/python/proton/__init__.py +++ b/proton-c/bindings/python/proton/__init__.py @@ -35,7 +35,10 @@ from cproton import * from .wrapper import Wrapper from proton import _compat -import weakref, socket, sys, threading +import logging, weakref, socket, sys, threading + +log = logging.getLogger("proton") +log.addHandler(logging.NullHandler()) try: import uuid @@ -4064,17 +4067,17 @@ class WrappedHandlersChildSurrogate: delegate = self.delegate() if delegate: dispatch(delegate, method, event) - + class WrappedHandlersProperty(object): def __get__(self, obj, clazz): if obj is None: return None return self.surrogate(obj).handlers - + def __set__(self, obj, value): self.surrogate(obj).handlers = value - + def surrogate(self, obj): key = "_surrogate" objdict = obj.__dict__ @@ -4085,7 +4088,7 @@ class WrappedHandlersProperty(object): return surrogate class WrappedHandler(Wrapper): - + handlers = WrappedHandlersProperty() @classmethod @@ -4096,7 +4099,7 @@ class WrappedHandler(Wrapper): handler = cls(impl) handler.__dict__["on_error"] = on_error return handler - + def __init__(self, impl_or_constructor): Wrapper.__init__(self, impl_or_constructor) if list(self.__class__.__mro__).index(WrappedHandler) > 1: http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/73aa2d7b/proton-c/bindings/python/proton/handlers.py ---------------------------------------------------------------------- diff --git a/proton-c/bindings/python/proton/handlers.py b/proton-c/bindings/python/proton/handlers.py index 6d3cce5..cd646aa 100644 --- a/proton-c/bindings/python/proton/handlers.py +++ b/proton-c/bindings/python/proton/handlers.py @@ -23,6 +23,7 @@ from proton import Collector, Connection, Delivery, Described, Endpoint, Event, from proton import Message, Handler, ProtonException, Transport, TransportException, ConnectionException from select import select +log = logging.getLogger("proton") class OutgoingMessageHandler(Handler): """ @@ -231,9 +232,9 @@ class EndpointStateHandler(Handler): @classmethod def print_error(cls, endpoint, endpoint_type): if endpoint.remote_condition: - logging.error(endpoint.remote_condition.description or endpoint.remote_condition.name) + log.error(endpoint.remote_condition.description or endpoint.remote_condition.name) elif cls.is_local_open(endpoint) and cls.is_remote_closed(endpoint): - logging.error("%s closed by peer" % endpoint_type) + log.error("%s closed by peer" % endpoint_type) def on_link_remote_close(self, event): if event.link.remote_condition: @@ -403,9 +404,9 @@ class MessagingHandler(Handler, Acking): """ if event.transport.condition: if event.transport.condition.info: - logging.error("%s: %s" % (event.transport.condition.name, event.transport.condition.description, event.transport.condition.info)) + log.error("%s: %s: %s" % (event.transport.condition.name, event.transport.condition.description, event.transport.condition.info)) else: - logging.error("%s: %s" % (event.transport.condition.name, event.transport.condition.description)) + log.error("%s: %s" % (event.transport.condition.name, event.transport.condition.description)) if event.transport.condition.name in self.fatal_conditions: event.connection.close() else: http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/73aa2d7b/proton-c/bindings/python/proton/reactor.py ---------------------------------------------------------------------- diff --git a/proton-c/bindings/python/proton/reactor.py b/proton-c/bindings/python/proton/reactor.py index 7b7c701..537b280 100644 --- a/proton-c/bindings/python/proton/reactor.py +++ b/proton-c/bindings/python/proton/reactor.py @@ -38,6 +38,8 @@ try: except ImportError: import queue as Queue +log = logging.getLogger("proton") + class Task(Wrapper): @staticmethod @@ -389,7 +391,7 @@ class Transaction(object): elif event.delivery.remote_state == Delivery.REJECTED: self.handler.on_transaction_declare_failed(event) else: - logging.warning("Unexpected outcome for declare: %s" % event.delivery.remote_state) + log.warning("Unexpected outcome for declare: %s" % event.delivery.remote_state) self.handler.on_transaction_declare_failed(event) elif event.delivery == self._discharge: if event.delivery.remote_state == Delivery.REJECTED: @@ -552,7 +554,7 @@ class Connector(Handler): # if virtual-host not set, use host from address as default if self.virtual_host is None: connection.hostname = url.host - logging.debug("connecting to %s..." % url) + log.debug("connecting to %s..." % url) transport = Transport() if self.sasl_enabled: @@ -583,7 +585,7 @@ class Connector(Handler): self._connect(event.connection, event.reactor) def on_connection_remote_open(self, event): - logging.debug("connected to %s" % event.connection.hostname) + log.debug("connected to %s" % event.connection.hostname) if self.reconnect: self.reconnect.reset() self.transport = None @@ -598,15 +600,15 @@ class Connector(Handler): event.transport.unbind() delay = self.reconnect.next() if delay == 0: - logging.info("Disconnected, reconnecting...") + log.info("Disconnected, reconnecting...") self._connect(self.connection, event.reactor) return else: - logging.info("Disconnected will try to reconnect after %s seconds" % delay) + log.info("Disconnected will try to reconnect after %s seconds" % delay) event.reactor.schedule(delay, self) return else: - logging.debug("Disconnected") + log.debug("Disconnected") # See connector.cpp: conn.free()/pn_connection_release() here? self.connection = None --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
