Author: rhs
Date: Tue Mar 11 07:29:17 2008
New Revision: 635939

URL: http://svn.apache.org/viewvc?rev=635939&view=rev
Log:
added convenience API for turning on logging; added logging for controls and 
commands; made logging prettier

Added:
    incubator/qpid/trunk/qpid/python/qpid/log.py
Modified:
    incubator/qpid/trunk/qpid/python/hello-010-world
    incubator/qpid/trunk/qpid/python/qpid/assembler.py
    incubator/qpid/trunk/qpid/python/qpid/connection010.py
    incubator/qpid/trunk/qpid/python/qpid/datatypes.py
    incubator/qpid/trunk/qpid/python/qpid/delegates.py
    incubator/qpid/trunk/qpid/python/qpid/framer.py
    incubator/qpid/trunk/qpid/python/qpid/session.py
    incubator/qpid/trunk/qpid/python/run-tests
    incubator/qpid/trunk/qpid/python/server010

Modified: incubator/qpid/trunk/qpid/python/hello-010-world
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/hello-010-world?rev=635939&r1=635938&r2=635939&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/hello-010-world (original)
+++ incubator/qpid/trunk/qpid/python/hello-010-world Tue Mar 11 07:29:17 2008
@@ -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)

Modified: incubator/qpid/trunk/qpid/python/qpid/assembler.py
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/assembler.py?rev=635939&r1=635938&r2=635939&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/assembler.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/assembler.py Tue Mar 11 07:29:17 2008
@@ -89,7 +89,7 @@
 
       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 @@
                     payload)
       self.write_frame(frame)
 
-    log.debug("SENT: %s", segment)
+    log.debug("SENT %s", segment)

Modified: incubator/qpid/trunk/qpid/python/qpid/connection010.py
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/connection010.py?rev=635939&r1=635938&r2=635939&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/connection010.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/connection010.py Tue Mar 11 07:29:17 
2008
@@ -27,6 +27,7 @@
 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 @@
   def __repr__(self):
     return str(self)
 
+log = getLogger("qpid.io.ctl")
+
 class Channel(Invoker):
 
   def __init__(self, connection, id):
@@ -164,11 +167,12 @@
       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)

Modified: incubator/qpid/trunk/qpid/python/qpid/datatypes.py
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/datatypes.py?rev=635939&r1=635938&r2=635939&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/datatypes.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/datatypes.py Tue Mar 11 07:29:17 2008
@@ -114,7 +114,7 @@
     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 @@
     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):

Modified: incubator/qpid/trunk/qpid/python/qpid/delegates.py
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/delegates.py?rev=635939&r1=635938&r2=635939&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/delegates.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/delegates.py Tue Mar 11 07:29:17 2008
@@ -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 @@
       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:

Modified: incubator/qpid/trunk/qpid/python/qpid/framer.py
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/framer.py?rev=635939&r1=635938&r2=635939&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/framer.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/framer.py Tue Mar 11 07:29:17 2008
@@ -88,7 +88,7 @@
           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 @@
       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 @@
     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 @@
     if end != "\xCE":
       raise FramingError()
     frame = Frame(flags, type, track, channel, payload)
-    frm.debug("RECV: %s", frame)
+    frm.debug("RECV %s", frame)
     return frame

Added: incubator/qpid/trunk/qpid/python/qpid/log.py
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/log.py?rev=635939&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/log.py (added)
+++ incubator/qpid/trunk/qpid/python/qpid/log.py Tue Mar 11 07:29:17 2008
@@ -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)

Modified: incubator/qpid/trunk/qpid/python/qpid/session.py
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/session.py?rev=635939&r1=635938&r2=635939&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/session.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/session.py Tue Mar 11 07:29:17 2008
@@ -28,6 +28,8 @@
 from exceptions import *
 from logging import getLogger
 
+log = getLogger("qpid.io.cmd")
+
 class SessionDetached(Exception): pass
 
 def client(*args):
@@ -142,6 +144,8 @@
 
     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 @@
 
   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 @@
     finally:
       self.session.lock.release()
 
-msg = getLogger("qpid.ssn.msg")
+msg = getLogger("qpid.io.msg")
 
 class Client(Delegate):
 
@@ -301,5 +308,5 @@
     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

Modified: incubator/qpid/trunk/qpid/python/run-tests
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/run-tests?rev=635939&r1=635938&r2=635939&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/run-tests (original)
+++ incubator/qpid/trunk/qpid/python/run-tests Tue Mar 11 07:29:17 2008
@@ -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)
 

Modified: incubator/qpid/trunk/qpid/python/server010
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/server010?rev=635939&r1=635938&r2=635939&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/server010 (original)
+++ incubator/qpid/trunk/qpid/python/server010 Tue Mar 11 07:29:17 2008
@@ -6,16 +6,16 @@
 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")
 


Reply via email to