You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by dr...@apache.org on 2008/06/11 00:55:38 UTC

svn commit: r666364 - /incubator/thrift/trunk/lib/py/src/server/TServer.py

Author: dreiss
Date: Tue Jun 10 15:55:38 2008
New Revision: 666364

URL: http://svn.apache.org/viewvc?rev=666364&view=rev
Log:
Change Python servers to use the standard logging module.

Previously Thrift was using `print` to report errors.  Thrift is infrastructure
and should not impose its error logging mechanism on the apps that use it.  For
example, [elided] uses the logging module to send logs to a particular file.

I ran the unit test.  That exercises most of the error handling routines.

Modified:
    incubator/thrift/trunk/lib/py/src/server/TServer.py

Modified: incubator/thrift/trunk/lib/py/src/server/TServer.py
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/py/src/server/TServer.py?rev=666364&r1=666363&r2=666364&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/py/src/server/TServer.py (original)
+++ incubator/thrift/trunk/lib/py/src/server/TServer.py Tue Jun 10 15:55:38 2008
@@ -6,6 +6,7 @@
 # See accompanying file LICENSE or visit the Thrift site at:
 # http://developers.facebook.com/thrift/
 
+import logging
 import sys
 import os
 import traceback
@@ -72,7 +73,7 @@
       except TTransport.TTransportException, tx:
         pass
       except Exception, x:
-        print '%s, %s, %s' % (type(x), x, traceback.format_exc())
+        logging.exception(x)
 
       itrans.close()
       otrans.close()
@@ -94,7 +95,7 @@
       except KeyboardInterrupt:
         raise
       except Exception, x:
-        print '%s, %s, %s,' % (type(x), x, traceback.format_exc())
+        logging.exception(x)
 
   def handle(self, client):
     itrans = self.inputTransportFactory.getTransport(client)
@@ -107,7 +108,7 @@
     except TTransport.TTransportException, tx:
       pass
     except Exception, x:
-      print '%s, %s, %s' % (type(x), x, traceback.format_exc())
+      logging.exception(x)
 
     itrans.close()
     otrans.close()
@@ -132,7 +133,7 @@
         client = self.clients.get()
         self.serveClient(client)
       except Exception, x:
-        print '%s, %s, %s' % (type(x), x, traceback.format_exc())
+        logging.exception(x)
 
   def serveClient(self, client):
     """Process input/output from a client for as long as possible"""
@@ -146,7 +147,7 @@
     except TTransport.TTransportException, tx:
       pass
     except Exception, x:
-      print '%s, %s, %s' % (type(x), x, traceback.format_exc())
+      logging.exception(x)
 
     itrans.close()
     otrans.close()
@@ -158,7 +159,7 @@
         t = threading.Thread(target = self.serveThread)
         t.start()
       except Exception, x:
-        print '%s, %s, %s,' % (type(x), x, traceback.format_exc())
+        logging.exception(x)
 
     # Pump the socket for clients
     self.serverTransport.listen()
@@ -167,7 +168,7 @@
         client = self.serverTransport.accept()
         self.clients.put(client)
       except Exception, x:
-        print '%s, %s, %s' % (type(x), x, traceback.format_exc())
+        logging.exception(x)
 
 
 class TForkingServer(TServer):
@@ -194,7 +195,7 @@
       try:
         file.close()
       except IOError, e:
-        print '%s, %s, %s' % (type(e), e, traceback.format_exc())
+        logging.warning(e, exc_info=True)
 
 
     self.serverTransport.listen()
@@ -228,7 +229,7 @@
           except TTransport.TTransportException, tx:
             pass
           except Exception, e:
-            print '%s, %s, %s' % (type(e), e, traceback.format_exc())
+            logging.exception(e)
             ecode = 1
           finally:
             try_close(itrans)
@@ -239,7 +240,7 @@
       except TTransport.TTransportException, tx:
         pass
       except Exception, x:
-        print '%s, %s, %s' % (type(x), x, traceback.format_exc())
+        logging.exception(x)
 
 
   def collect_children(self):