1. Lynn Rees
  2. wsgilog


Lynn Rees  committed 598f972

- fix

  • Participants
  • Parent commits eb41db6
  • Branches wsgilog

Comments (0)

Files changed (2)

File wsgilog/setup.py

View file
  • Ignore whitespace
     from distutils.core import setup
-      version='0.1',
+      version='0.2',
       description='''WSGI logging and event reporting middleware.''',
       long_description='''Supports logging events in WSGI applications to
 STDOUT, time rotated log files, email, syslog, and web servers. Also
     print 'STDOUT is logged.'
     environ['wsgilog.logger'].info('This information is logged.')
     # Exception will be logged and sent to the browser formatted as HTML.
-    raise Exception()  
+    raise Exception()
 if __name__ == '__main__':
     from wsgiref.simple_server import make_server
     http = make_server('', 8080, app)
-    http.serve_forever()       
+    http.serve_forever()
       author='L. C. Rees',

File wsgilog/wsgilog/__init__.py

View file
  • Ignore whitespace
-# Copyright (c) 2007 L. C. Rees.  All rights reserved.
+# Copyright (c) 2007-2009 L. C. Rees.  All rights reserved.
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions are met:
 '''WSGI logging and event reporting middleware.'''
+import pdb
 import sys
 import logging
 from cgitb import html
 # Current proposed 'environ' key signalling no middleware exception handling
 THROWERR = 'x-wsgiorg.throw_errors'
 # HTTP error messages
-HTTPMSG = '500 Internal error'
+HTTPMSG = '500 Internal Error'
 ERRORMSG = 'Server got itself in trouble'
 # Default log formats
 DATEFORMAT = '%a, %d %b %Y %H:%M:%S'
 def _errapp(environ, start_response):
     '''Default error handling WSGI application.'''
-    start_response(HTTPMSG, [('Content-type', 'text/plain')],
-        exc_info=sys.exc_info())
+    start_response(HTTPMSG, [('Content-type', 'text/plain')], sys.exc_info())
     return [ERRORMSG]    
 def log(**kw):
     return decorator
-class LogIO(object):
+class LogStdout(object):
     '''File-like object for sending stdout output to a logger.'''    
             assert self.logger.handlers, 'At least one logging handler must be configured'   
             # Redirect STDOUT to the logger
             if 'toprint' in kw:
-                sys.stdout = LogIO(self.logger,
+                sys.stdout = LogStdout(self.logger,
                     # Sets log level STDOUT is displayed under
-                    kw.get('prnlevel', logging.DEBUG))
+                    kw.get('prnlevel', logging.DEBUG))
+        # Flag for turning on PDB in situ
+        self.debug = kw.get('debug', False)
         # Flag for sending HTML-formatted exception tracebacks to the browser
         self.tohtml = kw.get('tohtml', False)
         # Write HTML-formatted exception tracebacks to a file if provided
     def catch(self, environ, start_response):
         '''Exception catcher.'''
         # Log exception
-        if self.log: self.logger.exception(self.message)
+        if self.log: self.logger.exception(self.message)
+        # Debug
+        if self.debug: pdb.pm()
         # Write HTML-formatted exception tracebacks to a file
         if self.htmlfile is not None:
             open(self.htmlfile, 'wb').write(html(sys.exc_info()))