Skip to content

Commit

Permalink
Merge pull request #1064 from lukebakken/pika-1060-master
Browse files Browse the repository at this point in the history
Add Pika version to connection logging
  • Loading branch information
michaelklishin committed Jun 6, 2018
2 parents 2a8c4ee + da0164c commit e1f0ef5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 9 additions & 2 deletions examples/consume.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import functools
import logging
import pika

LOG_FORMAT = ('%(levelname) -10s %(asctime)s %(name) -30s %(funcName) '
'-35s %(lineno) -5d: %(message)s')
LOGGER = logging.getLogger(__name__)

logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)

def on_message(channel, method_frame, header_frame, body, userdata=None):
print('Userdata: {} Message body: {}'.format(userdata, body))
LOGGER.info('Userdata: {} Message body: {}'.format(userdata, body))
channel.basic_ack(delivery_tag=method_frame.delivery_tag)

credentials = pika.PlainCredentials('guest', 'guest')
parameters = pika.ConnectionParameters('localhost', credentials=credentials)
parameters = pika.ConnectionParameters('localhost', credentials=credentials)
connection = pika.BlockingConnection(parameters)

channel = connection.channel()
Expand Down
4 changes: 3 additions & 1 deletion pika/adapters/utils/connection_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import pika.compat
import pika.exceptions
import pika.tcp_socket_opts
from pika import __version__


_LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -186,7 +187,8 @@ def start(self, addr_record, conn_params, on_done):
self._sock.setblocking(False)

addr = self._addr_record[4]
_LOG.info('Connecting to AMQP broker at %r', addr)
_LOG.info('Pika version %s connecting to %r',
__version__, addr)
self._task_ref = self._nbio.connect_socket(
self._sock,
addr,
Expand Down

0 comments on commit e1f0ef5

Please sign in to comment.