changeset 3281:d519735ca765

xmlrpc: use logging module
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 17 Mar 2008 10:29:18 +0100
parents ef1313a4add2
children 5aefbb27f8c5 bfd3f600650b
files MoinMoin/xmlrpc/UpdateGroup.py MoinMoin/xmlrpc/__init__.py
diffstat 2 files changed, 22 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/xmlrpc/UpdateGroup.py	Mon Mar 17 01:26:09 2008 +0100
+++ b/MoinMoin/xmlrpc/UpdateGroup.py	Mon Mar 17 10:29:18 2008 +0100
@@ -8,10 +8,11 @@
 
 import sys, xmlrpclib
 
+from MoinMoin import log
+logging = log.getLogger(__name__)
+
 from MoinMoin.PageEditor import PageEditor
 
-_debug = 0
-
 def execute(self, groupname, groupcomment, memberlist, pageacls=u"All:read"):
     """
     create or overwrite a group definition page
@@ -48,9 +49,10 @@
     try:
         msg = page.saveText(newtext, 0)
     except page.SaveError, msg:
+        logging.error("SaveError msg: %s" % str(msg))
         return xmlrpclib.Fault(3, msg)
-    if _debug and msg:
-        sys.stderr.write("Msg: %s\n" % msg)
+    if msg:
+        logging.debug("saveText msg: %s" % msg)
 
     #we need this to update pagelinks cache:
     self.request.args = self.request.form = self.request.setup_args({})
--- a/MoinMoin/xmlrpc/__init__.py	Mon Mar 17 01:26:09 2008 +0100
+++ b/MoinMoin/xmlrpc/__init__.py	Mon Mar 17 10:29:18 2008 +0100
@@ -17,7 +17,7 @@
     when really necessary (like for transferring binary files like
     attachments maybe).
 
-    @copyright: 2003-2007 MoinMoin:ThomasWaldmann,
+    @copyright: 2003-2008 MoinMoin:ThomasWaldmann,
                 2004-2006 MoinMoin:AlexanderSchremmer
     @license: GNU GPL, see COPYING for details
 """
@@ -27,6 +27,9 @@
 
 import os, sys, time, xmlrpclib
 
+from MoinMoin import log
+logging = log.getLogger(__name__)
+
 from MoinMoin import config, user, wikiutil
 from MoinMoin.Page import Page
 from MoinMoin.PageEditor import PageEditor
@@ -35,8 +38,6 @@
 from MoinMoin import caching
 from MoinMoin import session
 
-_debug = 0
-
 
 class XmlRpcAuthTokenIDHandler(session.SessionIDHandler):
     def __init__(self, token=None):
@@ -50,6 +51,8 @@
         self.token = session_id
 
 
+logging_tearline = '- XMLRPC %s ' + '-' * 40
+
 class XmlRpcBase:
     """ XMLRPC base class with common functionality of wiki xmlrpc v1 and v2 """
     def __init__(self, request):
@@ -132,21 +135,25 @@
                 data = self.request.read()
                 params, method = xmlrpclib.loads(data)
 
-                if _debug:
-                    sys.stderr.write('- XMLRPC ' + '-' * 70 + '\n')
-                    sys.stderr.write('%s(%s)\n\n' % (method, repr(params)))
+                logging.debug(logging_tearline % 'request begin')
+                logging.debug('%s(%s)' % (method, repr(params)))
+                logging.debug(logging_tearline % 'request end')
 
                 response = self.dispatch(method, params)
         except:
-            # report exception back to server
+            logging.exception("An exception occurred (this is also sent as fault response to the client):")
+            # report exception back to client
             response = xmlrpclib.dumps(xmlrpclib.Fault(1, self._dump_exc()))
         else:
+            logging.debug(logging_tearline % 'response begin')
+            logging.debug(response)
+            logging.debug(logging_tearline % 'response end')
+
             if isinstance(response, xmlrpclib.Fault):
                 response = xmlrpclib.dumps(response)
             else:
                 # wrap response in a singleton tuple
                 response = (response, )
-
                 # serialize it
                 response = xmlrpclib.dumps(response, methodresponse=1)
 
@@ -156,10 +163,6 @@
         ])
         self.request.write(response)
 
-        if _debug:
-            sys.stderr.write('- XMLRPC ' + '-' * 70 + '\n')
-            sys.stderr.write(response + '\n\n')
-
     def dispatch(self, method, params):
         """ call dispatcher - for method==xxx it either locates a method called
             xmlrpc_xxx or loads a plugin from plugin/xmlrpc/xxx.py
@@ -542,8 +545,7 @@
                 newtext = self._inlob(pagetext)
             msg = page.saveText(newtext, 0)
         except page.SaveError, msg:
-            if _debug:
-                sys.stderr.write("Msg: %s\n" % msg)
+            logging.error("SaveError: %s" % msg)
             return xmlrpclib.Fault(1, "%s" % msg)
 
         # Update pagelinks cache