Exemplo n.º 1
0
 def makeRecord(self, name, level, fn, lno, msg, args, exc_info, func=None, extra=None):
     try:
         from splunk.appserver.mrsparkle.lib.util import get_request_id
         if extra is None:
             extra = {}
         extra['requestid'] = get_request_id()
     except ImportError, e:
         extra = {'requestid': '-'}
Exemplo n.º 2
0
    def access(self):
        """Write to the access log (in Apache/NCSA Combined Log format).
        
        Like Apache started doing in 2.0.46, non-printable and other special
        characters in %r (and we expand that to all parts) are escaped using
        \\xhh sequences, where hh stands for the hexadecimal representation
        of the raw byte. Exceptions from this rule are " and \\, which are
        escaped by prepending a backslash, and all whitespace characters,
        which are written in their C-style notation (\\n, \\t, etc).
        """
        request = cherrypy.request
        remote = request.remote
        response = cherrypy.serving.response
        outheaders = response.headers
        inheaders = request.headers

        try:
            username = cherrypy.session['user']['name']
        except:
            username = None

        atoms = {
            'h': remote.name or remote.ip,
            'l': '-',
            'u': username or "-",
            't': self.access_time(response.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', ''),
        }
        for k, v in atoms.items():
            if isinstance(v, unicode):
                v = v.encode('utf8')
            elif not isinstance(v, str):
                v = str(v)
            # Fortunately, repr(str) escapes unprintable chars, \n, \t, etc
            # and backslash for us. All we have to do is strip the quotes.
            v = repr(v)[1:-1]
            # Escape double-quote.
            atoms[k] = v.replace('"', '\\"')

        try:
            # the dash before the request id in this line represents a virtual host name that
            # we're not currently logging, but might in the future.
            # Some web log analysis tools expect the combined log format to have a vhost name in it.
            self.access_log.log(
                logging.INFO, (self.access_log_format % atoms) +
                (' - %s %dms' %
                 (get_request_id(), round(
                     (time.time() - response.time) * 1000))))
        except:
            self(traceback=True)
Exemplo n.º 3
0
 def makeRecord(self,
                name,
                level,
                fn,
                lno,
                msg,
                args,
                exc_info,
                func=None,
                extra=None):
     from splunk.appserver.mrsparkle.lib.util import get_request_id
     if extra is None:
         extra = {}
     extra['requestid'] = get_request_id()
     return logging.Logger.makeRecord(self, name, level, fn, lno, msg, args,
                                      exc_info, func, extra)
Exemplo n.º 4
0
 def makeRecord(self, name, level, fn, lno, msg, args, exc_info, func=None, extra=None):
     from splunk.appserver.mrsparkle.lib.util import get_request_id
     if extra is None:
         extra = {}
     extra['requestid'] = get_request_id()
     return logging.Logger.makeRecord(self, name, level, fn, lno, msg, args, exc_info, func, extra)
Exemplo n.º 5
0
    def access(self):
        """Write to the access log (in Apache/NCSA Combined Log format).
        
        Like Apache started doing in 2.0.46, non-printable and other special
        characters in %r (and we expand that to all parts) are escaped using
        \\xhh sequences, where hh stands for the hexadecimal representation
        of the raw byte. Exceptions from this rule are " and \\, which are
        escaped by prepending a backslash, and all whitespace characters,
        which are written in their C-style notation (\\n, \\t, etc).
        """
        request = cherrypy.request
        remote = request.remote
        response = cherrypy.serving.response
        outheaders = response.headers
        inheaders = request.headers

        try:
            username = cherrypy.session['user']['name']
        except:
            username = None

        atoms = {'h': remote.name or remote.ip,
                 'l': '-',
                 'u': username or "-",
                 't': self.access_time(response.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', ''),
                 }
        for k, v in atoms.items():
            if isinstance(v, unicode):
                v = v.encode('utf8')
            elif not isinstance(v, str):
                v = str(v)
            # Fortunately, repr(str) escapes unprintable chars, \n, \t, etc
            # and backslash for us. All we have to do is strip the quotes.
            v = repr(v)[1:-1]
            # Escape double-quote.
            atoms[k] = v.replace('"', '\\"')
        
        try:
            # the dash before the request id in this line represents a virtual host name that
            # we're not currently logging, but might in the future.  
            # Some web log analysis tools expect the combined log format to have a vhost name in it.
            self.access_log.log(logging.INFO, (self.access_log_format % atoms) + (' - %s %dms' % (get_request_id(), round((time.time() - response.time)*1000))))
        except:
            self(traceback=True)