import traceback

class LoggingMiddleware(object):
    def process_job(self, job):
        print "I: Running job %s" % job

    def process_result(self, job, result, duration):
        print "I: Finished job %s => %r (Time taken: %.2fs)" % (
            job,
            result,
            duration,
        )

    def process_exception(self, job, time_taken, *exc_info):
        traceback.print_exception(*exc_info)

@@ -1,20 +1,58 @@
-import traceback
+from __future__ import absolute_import%0A%0Aimport logging
 %0A%0Acl
@@ -122,26 +122,30 @@
         
-print %22I: 
+logging.info(%22
 Running 
@@ -155,14 +155,14 @@
  %25s%22
- %25
+,
  job
+)
 %0A%0A  
@@ -224,18 +224,22 @@
     
-print %22I: 
+logging.info(%22
 Fini
@@ -280,12 +280,9 @@
 fs)%22
- %25 (
+,
 %0A   
@@ -389,17 +389,15 @@
 ob, 
-time_take
+duratio
 n, *
@@ -407,16 +407,135 @@
 _info):%0A
+        logging.error(%22Exception when processing %25r (duration: %25.2fs): %25s%22,%0A            job,%0A            duration,%0A    
         
@@ -548,12 +548,13 @@
 ack.
-prin
+forma
 t_ex
@@ -571,9 +571,20 @@
 xc_info)
+,%0A        )
 %0A

Use logging framework.