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

Changeset 1811

Show
Ignore:
Timestamp:
10/29/07 19:27:35
Author:
fumanchu
Message:

Fix for #745 (Make a builtin tool which logs all hooks for a given request).

Files:

Legend:

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

    r1786 r1811  
    5757        """Run self.callback(**self.kwargs).""" 
    5858        return self.callback(**self.kwargs) 
     59     
     60    def __repr__(self): 
     61        cls = self.__class__ 
     62        return ("%s.%s(callback=%r, failsafe=%r, priority=%r, %s)" 
     63                % (cls.__module__, cls.__name__, self.callback, 
     64                   self.failsafe, self.priority, 
     65                   ", ".join(['%s=%r' % (k, v) 
     66                              for k, v in self.kwargs.iteritems()]))) 
    5967 
    6068 
  • trunk/cherrypy/_cptools.py

    r1770 r1811  
    428428_d.log_tracebacks = Tool('before_error_response', cptools.log_traceback) 
    429429_d.log_headers = Tool('before_error_response', cptools.log_request_headers) 
     430_d.log_hooks = Tool('on_end_request', cptools.log_hooks, priority=100) 
    430431_d.err_redirect = ErrorTool(cptools.redirect) 
    431432_d.etags = Tool('before_finalize', cptools.validate_etags) 
  • trunk/cherrypy/lib/cptools.py

    r1767 r1811  
    296296    h = ["  %s: %s" % (k, v) for k, v in cherrypy.request.header_list] 
    297297    cherrypy.log('\nRequest Headers:\n' + '\n'.join(h), "HTTP") 
     298 
     299def log_hooks(): 
     300    """Write request.hooks to the cherrypy error log.""" 
     301    msg = [] 
     302    # Sort by the standard points if possible. 
     303    from cherrypy import _cprequest 
     304    points = _cprequest.hookpoints 
     305    for k in cherrypy.request.hooks.keys(): 
     306        if k not in points: 
     307            points.append(k) 
     308     
     309    for k in points: 
     310        msg.append("    %s:" % k) 
     311        v = cherrypy.request.hooks.get(k, []) 
     312        v.sort() 
     313        for h in v: 
     314            msg.append("        %r" % h) 
     315    cherrypy.log('\nRequest Hooks:\n' + '\n'.join(msg), "HTTP") 
    298316 
    299317def redirect(url='', internal=True): 
  • trunk/cherrypy/test/test_misc_tools.py

    r1657 r1811  
    11from cherrypy.test import test 
    22test.prefer_parent_path() 
     3 
     4import os 
     5localDir = os.path.dirname(__file__) 
     6logfile = os.path.join(localDir, "test_misc_tools.log") 
    37 
    48import cherrypy 
     
    2125            'tools.response_headers.headers': [("Content-Language", "fr"), 
    2226                                               ('Content-Type', 'text/plain')], 
     27            'tools.log_hooks.on': True, 
    2328            } 
    2429     
     
    6873    root.accept = Accept() 
    6974    cherrypy.tree.mount(root, config=conf) 
    70     cherrypy.config.update({'environment': 'test_suite'}) 
     75    cherrypy.config.update({'environment': 'test_suite', 
     76                            'log.error_file': logfile}) 
    7177 
    7278 

Hosted by WebFaction

Log in as guest/cpguest to create tickets