Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 805

Show
Ignore:
Timestamp:
11/10/05 00:04:09
Author:
fumanchu
Message:

Fix for #386 (separate config entry for logging unhandled exceptions).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/_cphttptools.py

    r794 r805  
    11"""CherryPy core request/response handling.""" 
    22 
    3 import cgi 
    43import Cookie 
    54import os 
    6 import re 
    75import sys 
    86import types 
  • trunk/cherrypy/_cputil.py

    r800 r805  
    306306def _cpOnError(): 
    307307    """ Default _cpOnError method """ 
     308    # Allow logging of only *unexpected* HTTPError's. 
     309    if (not cherrypy.config.get('server.logTracebacks', True) 
     310        and cherrypy.config.get('server.logUnhandledTracebacks', True)): 
     311        cherrypy.log(formatExc()) 
     312     
    308313    cherrypy.HTTPError(500).set_response() 
    309314 
  • trunk/cherrypy/test/test_core.py

    r801 r805  
    171171        # Since status must start with an int, this should error. 
    172172        cherrypy.response.status = "ZOO OK" 
     173     
     174    def log_unhandled(self): 
     175        raise ValueError() 
    173176 
    174177 
     
    353356        'errorPage.404': "nonexistent.html", 
    354357    }, 
     358    '/error/log_unhandled': { 
     359        'server.logTracebacks': False, 
     360        'server.logUnhandledTracebacks': True, 
     361    }, 
    355362}) 
    356363 
     
    453460        self.assertEqual(data, []) 
    454461         
    455         # Test that tracebacks get written to the error log. 
    456462        ignore = helper.webtest.ignored_exceptions 
    457463        ignore.append(ValueError) 
    458464        try: 
     465            # Test that tracebacks get written to the error log. 
    459466            self.getPage("/error/page_method") 
    460467            self.assertInBody("raise ValueError()") 
     
    462469            self.assertEqual(data[0][-41:], ' INFO Traceback (most recent call last):\n') 
    463470            self.assertEqual(data[6], '    raise ValueError()\n') 
     471             
     472            # Test that unhandled tracebacks get written to the error log 
     473            # if logTracebacks is False but logUnhandledTracebacks is True. 
     474            self.getPage("/error/log_unhandled") 
     475            self.assertInBody("raise ValueError()") 
     476            data = open(logFile, "rb").readlines() 
     477            self.assertEqual(data[9][-41:], ' INFO Traceback (most recent call last):\n') 
     478            self.assertEqual(data[15], '    raise ValueError()\n') 
     479            # Each error should write only one traceback (9 lines each). 
     480            self.assertEqual(len(data), 18) 
    464481        finally: 
    465482            ignore.pop() 

Hosted by WebFaction

Log in as guest/cpguest to create tickets