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

Ticket #727 (defect)

Opened 1 year ago

Last modified 1 year ago

Access log does not contain referer and user-agent

Status: closed (fixed)

Reported by: carstengrohmann@gmx.de Assigned to: rdelon
Priority: normal Milestone:
Component: CherryPy code Keywords:
Cc:

Currently I've lines like

172.20.226.49 - - [06/Sep/2007:10:37:19] "GET /img/img_18.gif HTTP/1.1" 304 - "" ""

in my access log. I miss the entries of user agent and referer.

The function LogManager.access() uses the response object to get those two fields. But only the request object contains the elements.

Current:

def access(self): 
    """Write to the access log.""" 
    request = cherrypy.request 
    remote = request.remote 
    response = cherrypy.response 
    outheaders = response.headers 
    tmpl = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"' 
    s = tmpl % {'h': remote.name or remote.ip, 
                'l': '-', 
                'u': getattr(request, "login", None) or "-", 
                't': self.time(), 
                'r': request.request_line, 
                's': response.status.split(" ", 1)[0], 
                'b': outheaders.get('Content-Length', '') or "-", 
                'f': outheaders.get('referer', ''), 
                'a': outheaders.get('user-agent', ''), 
                } 
    try: 
        self.access_log.log(logging.INFO, s) 
    except: 
        self(traceback=True) 

New:

def access(self): 
    """Write to the access log.""" 
    request = cherrypy.request 
    inheaders = request.headers
    remote = request.remote 
    response = cherrypy.response 
    outheaders = response.headers 
    tmpl = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"' 
    s = tmpl % {'h': remote.name or remote.ip, 
                'l': '-', 
                'u': getattr(request, "login", None) or "-", 
                't': self.time(), 
                'r': request.request_line, 
                's': response.status.split(" ", 1)[0], 
                'b': outheaders.get('Content-Length', '') or "-", 
                'f': inheaders.get('referer', ''), 
                'a': inheaders.get('user-agent', ''), 
                } 
    try: 
        self.access_log.log(logging.INFO, s) 
    except: 
        self(traceback=True)

Regards,

Carsten

Change History

09/06/07 15:58:05: Modified by fumanchu

  • status changed from new to closed.
  • resolution set to fixed.

Thanks! Fixed in trunk in [1717]. Needs a backport to 3.0.x.

Hosted by WebFaction

Log in as guest/cpguest to create tickets