diff options
author | Rafael H. Schloming <rhs@apache.org> | 2008-03-11 14:29:17 +0000 |
---|---|---|
committer | Rafael H. Schloming <rhs@apache.org> | 2008-03-11 14:29:17 +0000 |
commit | 5c70b29392ab7f7252d7923d98616794f6200eab (patch) | |
tree | 23caf5119ab5bc73530d4d3747ca56ce16838de4 | |
parent | d38d509af075300441ad858b1bb7680ac6b8e5ca (diff) | |
download | qpid-python-5c70b29392ab7f7252d7923d98616794f6200eab.tar.gz |
added convenience API for turning on logging; added logging for controls and commands; made logging prettier
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@635939 13f79535-47bb-0310-9956-ffa450edef68
-rwxr-xr-x | python/hello-010-world | 11 | ||||
-rw-r--r-- | python/qpid/assembler.py | 4 | ||||
-rw-r--r-- | python/qpid/connection010.py | 8 | ||||
-rw-r--r-- | python/qpid/datatypes.py | 4 | ||||
-rw-r--r-- | python/qpid/delegates.py | 10 | ||||
-rw-r--r-- | python/qpid/framer.py | 8 | ||||
-rw-r--r-- | python/qpid/log.py | 28 | ||||
-rw-r--r-- | python/qpid/session.py | 11 | ||||
-rwxr-xr-x | python/run-tests | 8 | ||||
-rwxr-xr-x | python/server010 | 10 |
10 files changed, 73 insertions, 29 deletions
diff --git a/python/hello-010-world b/python/hello-010-world index 83e7c87675..a15817cd9d 100755 --- a/python/hello-010-world +++ b/python/hello-010-world @@ -1,18 +1,19 @@ #!/usr/bin/env python -import sys, logging +import sys from qpid.connection010 import Connection from qpid.spec010 import load from qpid.util import connect from qpid.datatypes import Message, RangedSet +from qpid.log import enable, DEBUG, WARN if "-v" in sys.argv: - level = logging.DEBUG + level = DEBUG else: - level = logging.WARN + level = WARN -format = "%(asctime)s %(name)-12s %(levelname)-8s %(message)s" -logging.basicConfig(level=level, format=format, datefmt='%H:%M:%S') +enable("qpid.io.ctl", level) +enable("qpid.io.cmd", level) spec = load("../specs/amqp.0-10.xml") conn = Connection(connect("0.0.0.0", spec.port), spec) diff --git a/python/qpid/assembler.py b/python/qpid/assembler.py index 9f8bc4bd8a..92bb0aa0f8 100644 --- a/python/qpid/assembler.py +++ b/python/qpid/assembler.py @@ -89,7 +89,7 @@ class Assembler(Framer): if frame.isLastFrame(): self.fragments.pop(key) - log.debug("RECV: %s", seg) + log.debug("RECV %s", seg) return seg def write_segment(self, segment): @@ -115,4 +115,4 @@ class Assembler(Framer): payload) self.write_frame(frame) - log.debug("SENT: %s", segment) + log.debug("SENT %s", segment) diff --git a/python/qpid/connection010.py b/python/qpid/connection010.py index 1235476b82..59aa41c88d 100644 --- a/python/qpid/connection010.py +++ b/python/qpid/connection010.py @@ -27,6 +27,7 @@ from session import Session from invoker import Invoker from spec010 import Control, Command from exceptions import * +from logging import getLogger import delegates class ChannelBusy(Exception): pass @@ -149,6 +150,8 @@ class Connection(Assembler): def __repr__(self): return str(self) +log = getLogger("qpid.io.ctl") + class Channel(Invoker): def __init__(self, connection, id): @@ -164,11 +167,12 @@ class Channel(Invoker): return None def invoke(self, type, args, kwargs): - cntrl = type.new(args, kwargs) + ctl = type.new(args, kwargs) sc = StringCodec(self.connection.spec) - sc.write_control(cntrl) + sc.write_control(ctl) self.connection.write_segment(Segment(True, True, type.segment_type, type.track, self.id, sc.encoded)) + log.debug("SENT %s", ctl) def __str__(self): return "%s[%s]" % (self.connection, self.id) diff --git a/python/qpid/datatypes.py b/python/qpid/datatypes.py index 45944a2494..96ef94de8a 100644 --- a/python/qpid/datatypes.py +++ b/python/qpid/datatypes.py @@ -114,7 +114,7 @@ class Range: return Range(min(self.lower, r.lower), max(self.upper, r.upper)) def __repr__(self): - return "Range(%s, %s)" % (self.lower, self.upper) + return "%s-%s" % (self.lower, self.upper) class RangedSet: @@ -147,7 +147,7 @@ class RangedSet: self.add_range(Range(lower, upper)) def __repr__(self): - return "RangedSet(%s)" % str(self.ranges) + return str(self.ranges) class Future: def __init__(self, initial=None, exception=Exception): diff --git a/python/qpid/delegates.py b/python/qpid/delegates.py index 8de7141962..9df2cd04bd 100644 --- a/python/qpid/delegates.py +++ b/python/qpid/delegates.py @@ -20,6 +20,9 @@ import os, connection010, session from util import notify from datatypes import RangedSet +from logging import getLogger + +log = getLogger("qpid.io.ctl") class Delegate: @@ -37,9 +40,10 @@ class Delegate: ch = ssn.channel if seg.track == self.control: - cntrl = seg.decode(self.spec) - attr = cntrl._type.qname.replace(".", "_") - getattr(self, attr)(ch, cntrl) + ctl = seg.decode(self.spec) + log.debug("RECV %s", ctl) + attr = ctl._type.qname.replace(".", "_") + getattr(self, attr)(ch, ctl) elif ssn is None: ch.session_detached() else: diff --git a/python/qpid/framer.py b/python/qpid/framer.py index 3cc200e3da..11fe385d46 100644 --- a/python/qpid/framer.py +++ b/python/qpid/framer.py @@ -88,7 +88,7 @@ class Framer(Packer): raise Closed() else: continue - raw.debug("SENT: %r", buf[:n]) + raw.debug("SENT %r", buf[:n]) buf = buf[n:] def read(self, n): @@ -109,7 +109,7 @@ class Framer(Packer): if len(s) == 0: raise Closed() data += s - raw.debug("RECV: %r", s) + raw.debug("RECV %r", s) return data def read_header(self): @@ -125,7 +125,7 @@ class Framer(Packer): self.write(frame.payload) # XXX: NOT 0-10 FINAL, TEMPORARY WORKAROUND for C++ self.write("\xCE") - frm.debug("SENT: %s", frame) + frm.debug("SENT %s", frame) def read_frame(self): flags, type, size, track, channel = self.unpack(Frame.HEADER) @@ -136,5 +136,5 @@ class Framer(Packer): if end != "\xCE": raise FramingError() frame = Frame(flags, type, track, channel, payload) - frm.debug("RECV: %s", frame) + frm.debug("RECV %s", frame) return frame diff --git a/python/qpid/log.py b/python/qpid/log.py new file mode 100644 index 0000000000..1fd7d74136 --- /dev/null +++ b/python/qpid/log.py @@ -0,0 +1,28 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +from logging import getLogger, StreamHandler, Formatter +from logging import DEBUG, INFO, WARN, ERROR, CRITICAL + +def enable(name=None, level=WARN, file=None): + log = getLogger(name) + handler = StreamHandler(file) + handler.setFormatter(Formatter("%(asctime)s %(levelname)s %(message)s")) + log.addHandler(handler) + log.setLevel(level) diff --git a/python/qpid/session.py b/python/qpid/session.py index 8374b8cd3d..4da6f883b4 100644 --- a/python/qpid/session.py +++ b/python/qpid/session.py @@ -28,6 +28,8 @@ from util import wait, notify from exceptions import * from logging import getLogger +log = getLogger("qpid.io.cmd") + class SessionDetached(Exception): pass def client(*args): @@ -142,6 +144,8 @@ class Session(Invoker): self.send(seg) + log.debug("SENT %s %s %s", seg.id, hdr, cmd) + if message != None: if message.headers != None: sc = StringCodec(self.spec) @@ -175,7 +179,10 @@ class Session(Invoker): def dispatch(self, assembly): segments = assembly[:] + hdr, cmd = assembly.pop(0).decode(self.spec) + log.debug("RECV %s %s %s", cmd.id, hdr, cmd) + args = [] for st in cmd._type.segments: @@ -291,7 +298,7 @@ class Delegate: finally: self.session.lock.release() -msg = getLogger("qpid.ssn.msg") +msg = getLogger("qpid.io.msg") class Client(Delegate): @@ -301,5 +308,5 @@ class Client(Delegate): m.id = cmd.id messages = self.session.incoming(cmd.destination) messages.put(m) - msg.debug("RECV: %s", m) + msg.debug("RECV %s", m) return INCOMPLETE diff --git a/python/run-tests b/python/run-tests index 07162efd15..84b76ebfc1 100755 --- a/python/run-tests +++ b/python/run-tests @@ -20,14 +20,14 @@ import sys, logging from qpid.testlib import testrunner +from qpid.log import enable, WARN, DEBUG if "-vv" in sys.argv: - level = logging.DEBUG + level = DEBUG else: - level = logging.WARN + level = WARN -format = "%(asctime)s %(name)-12s %(levelname)-8s %(message)s" -logging.basicConfig(level=level, format=format, datefmt='%H:%M:%S') +enable("qpid", level) if not testrunner.run(): sys.exit(1) diff --git a/python/server010 b/python/server010 index 7b4b5762ca..0a75e2534e 100755 --- a/python/server010 +++ b/python/server010 @@ -6,16 +6,16 @@ from qpid.util import connect, listen from qpid.spec010 import load from qpid.session import Client from qpid.datatypes import Message +from qpid.log import enable, DEBUG, WARN -import logging, sys +import sys if "-v" in sys.argv: - level = logging.DEBUG + level = DEBUG else: - level = logging.WARN + level = WARN -format = "%(asctime)s %(name)-12s %(levelname)-8s %(message)s" -logging.basicConfig(level=level, format=format, datefmt='%H:%M:%S') +enable("qpid", level) spec = load("../specs/amqp.0-10.xml") |