Author: jonathan
Date: Wed Dec 22 22:22:13 2010
New Revision: 1052086

URL: http://svn.apache.org/viewvc?rev=1052086&view=rev
Log:
Added logging to QMF console connections.

Warning if a broker can not be found, error if SASL authentication fails or 
other connection errors when connecting to an existing broker.  Default log 
level is ERROR.

qpid-printevents allows the log level to be set. It also allows the user to 
specify that a connection is required, in which case it terminates if a 
connection can not be established.

Examples: 

$ ./qpid-printevents --sasl-mechanism PLAIN nonexistent-broker

=> Not an error. Waits for the broker to be started.

$ ./qpid-printevents --sasl-mechanism PLAIN localhost
2010-12-22 17:07:18,365 ERROR Could not connect to broker localhost:5672 (None, 
'No acceptable SASL authentication mechanism available')

=> Connection error condition in output - SASL authentication failed
   because user name and password are not supplied.

   But qpid-printevents keeps running, waiting for you to start the
   broker.

$ ./qpid-printevents --sasl-mechanism PLAIN --log-level critical

=> Connection error condition in output - SASL authentication failed
   because user name and password are not supplied.

   No output in this case, because the log level has been set to
   critical.

$ ./qpid-printevents --sasl-mechanism PLAIN --require-connection localhost
2010-12-22 17:11:03,791 ERROR Could not connect to broker localhost:5672 (None, 
'No acceptable SASL authentication mechanism available')
Failed: ConnectionFailed - (None, 'No acceptable SASL authentication mechanism 
available')

=> Connection error condition.

   qpid-printevents terminates because --require-connection was specified.


Modified:
    qpid/trunk/qpid/extras/qmf/src/py/qmf/console.py
    qpid/trunk/qpid/tools/src/py/qpid-config
    qpid/trunk/qpid/tools/src/py/qpid-printevents
    qpid/trunk/qpid/tools/src/py/qpid-stat
    qpid/trunk/qpid/tools/src/py/qpid-tool

Modified: qpid/trunk/qpid/extras/qmf/src/py/qmf/console.py
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/extras/qmf/src/py/qmf/console.py?rev=1052086&r1=1052085&r2=1052086&view=diff
==============================================================================
--- qpid/trunk/qpid/extras/qmf/src/py/qmf/console.py (original)
+++ qpid/trunk/qpid/extras/qmf/src/py/qmf/console.py Wed Dec 22 22:22:13 2010
@@ -39,8 +39,8 @@ from Queue           import Queue, Empty
 from time            import time, strftime, gmtime, sleep
 from cStringIO       import StringIO
 
-#import qpid.log
-#qpid.log.enable(name="qpid.io.cmd", level=qpid.log.DEBUG)
+import qpid.log
+qpid.log.enable(name="qpid.qmf")
 
 
#===================================================================================================
 # CONSOLE
@@ -2509,6 +2509,14 @@ class Broker(Thread):
 
     except Exception, e:
       self.error = "Exception during connection setup: %s - %s" % 
(e.__class__.__name__, e)
+
+      log = qpid.log.getLogger("qpid.qmf")
+      
+      if e[0] == -2:
+          log.warning("Could not connect to broker " + self.host + ":" + 
str(self.port) + " " + str(e))
+      else:
+          log.error("Could not connect to broker " + self.host + ":" + 
str(self.port) + " " + str(e))
+
       self.conn_exc = e
       return False     # connection failed
 

Modified: qpid/trunk/qpid/tools/src/py/qpid-config
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/py/qpid-config?rev=1052086&r1=1052085&r2=1052086&view=diff
==============================================================================
--- qpid/trunk/qpid/tools/src/py/qpid-config (original)
+++ qpid/trunk/qpid/tools/src/py/qpid-config Wed Dec 22 22:22:13 2010
@@ -24,6 +24,7 @@ from optparse import OptionParser, Optio
 import sys
 import locale
 from qmf.console import Session
+import qpid.log
 
 class Config:
     def __init__(self):
@@ -546,6 +547,9 @@ def YN(bool):
 
 
 def main(argv=None):
+
+    qpid.log.getLogger("qpid.qmf").setLevel(qpid.log.ERROR)
+
     args = OptionsAndArguments(argv)
     bm   = BrokerManager()
 
@@ -591,13 +595,13 @@ def main(argv=None):
     except KeyboardInterrupt:
         print
     except IOError, e:
-        print e
+        print "Failed: %s: %s" % (e.__class__.__name__, e)
         bm.Disconnect()
         return 1
     except SystemExit, e:
         bm.Disconnect()
         return 1
-    except Exception,e:
+    except Exception, e:
         if e.__class__.__name__ != "Timeout":
             # ignore Timeout exception, handle in the loop below
             print "Failed: %s: %s" % (e.__class__.__name__, e)

Modified: qpid/trunk/qpid/tools/src/py/qpid-printevents
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/py/qpid-printevents?rev=1052086&r1=1052085&r2=1052086&view=diff
==============================================================================
--- qpid/trunk/qpid/tools/src/py/qpid-printevents (original)
+++ qpid/trunk/qpid/tools/src/py/qpid-printevents Wed Dec 22 22:22:13 2010
@@ -26,7 +26,7 @@ import sys
 import socket
 from time import time, strftime, gmtime, sleep
 from qmf.console import Console, Session
-
+import qpid.log
 
 class EventConsole(Console):
   def event(self, broker, event):
@@ -75,26 +75,52 @@ $ %prog guest/gu...@broker-host:10000
 """
 
 def main(argv=None):
+
   p = optparse.OptionParser(usage=_usage, description=_description, 
formatter=JHelpFormatter())
   p.add_option("--heartbeats", action="store_true", default=False, help="Use 
heartbeats.")
   p.add_option("--sasl-mechanism", action="store", 
choices=["EXTERNAL","ANONYMOUS","PLAIN","CRAM-MD5","DIGEST-MD5","GSSAPI"], 
metavar="<mech>", help="SASL mechanism for authentication. SASL automatically 
picks the most secure available mechanism - use this option to override.")
+  p.add_option("--require-connection", action="store_true", help="Raise error 
if connection can not be established. By default, retries connections that 
could not be established, which allows events to be printed as brokers start 
and stop.")
+  p.add_option("--log-level", action="store", choices=["debug", "info", 
"warn", "error", "critical"], metavar="<level>", help="Logging level for 
connections")
+
 
   options, arguments = p.parse_args(args=argv)
   if len(arguments) == 0:
     arguments.append("localhost")
 
+  LOG_LEVELS = {'debug': qpid.log.DEBUG,
+                'info': qpid.log.INFO,
+                'warn': qpid.log.WARN,
+                'error': qpid.log.ERROR,
+                'critical': qpid.log.CRITICAL}
+
+  if options.require_connection:
+    manageConnections=False
+  else:
+    manageConnections=True
+
+  if options.log_level:
+    qpid.log.getLogger("qpid.qmf").setLevel(LOG_LEVELS[options.log_level])
+  else:
+    qpid.log.getLogger("qpid.qmf").setLevel(qpid.log.ERROR)
+
   console = EventConsole()
-  session = Session(console, rcvObjects=False, 
rcvHeartbeats=options.heartbeats, manageConnections=True)
+  session = Session(console, rcvObjects=False, 
rcvHeartbeats=options.heartbeats, manageConnections=manageConnections)
   brokers = []
   try:
     for host in arguments:
       brokers.append(session.addBroker(host, None, options.sasl_mechanism))
-    try:
+
       while (True):
         sleep(10)
-    except KeyboardInterrupt:
+
+  except KeyboardInterrupt:
       print
-      sys.exit(0)
+      return 0
+
+  except Exception, e:
+      print "Failed: %s - %s" % (e.__class__.__name__, e)
+      return 1
+
   finally:
     while len(brokers):
       b = brokers.pop()

Modified: qpid/trunk/qpid/tools/src/py/qpid-stat
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/py/qpid-stat?rev=1052086&r1=1052085&r2=1052086&view=diff
==============================================================================
--- qpid/trunk/qpid/tools/src/py/qpid-stat (original)
+++ qpid/trunk/qpid/tools/src/py/qpid-stat Wed Dec 22 22:22:13 2010
@@ -511,7 +511,7 @@ def main(argv=None):
         return 0
     except KeyboardInterrupt:
         print
-    except Exception,e:
+    except Exception, e:
         print "Failed: %s - %s" % (e.__class__.__name__, e)
 
     bm.Disconnect()   # try to deallocate brokers

Modified: qpid/trunk/qpid/tools/src/py/qpid-tool
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/py/qpid-tool?rev=1052086&r1=1052085&r2=1052086&view=diff
==============================================================================
--- qpid/trunk/qpid/tools/src/py/qpid-tool (original)
+++ qpid/trunk/qpid/tools/src/py/qpid-tool Wed Dec 22 22:22:13 2010
@@ -30,6 +30,7 @@ from time        import strftime, gmtime
 from qpid.disp   import Display
 from qpid.peer   import Closed
 from qmf.console import Session, Console, SchemaClass, ObjectId
+import qpid.log
 
 class Mcli(Cmd):
   """ Management Command Interpreter """
@@ -677,6 +678,8 @@ def Usage():
 # Main Program
 #=========================================================
 
+qpid.log.getLogger("qpid.qmf").setLevel(qpid.log.ERROR)
+
 # Get host name and port if specified on the command line
 cargs = sys.argv[1:]
 _host = "localhost"
@@ -692,6 +695,7 @@ if _host[0] == '-':
 
 disp = Display()
 
+
 # Attempt to make a connection to the target broker
 try:
   data = QmfData(disp, _host)



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:[email protected]

Reply via email to