# HG changeset patch # User Marcin Kuzminski # Date 2019-07-18 16:13:04 # Node ID 1f21fc7ef7f61b1c6c22d666cebd3902a4ba98ec # Parent 1cfce40fcd9c419d31cca813601eac82a3759ab1 request-wrapper: set custom module for better logging. diff --git a/vcsserver/http_main.py b/vcsserver/http_main.py --- a/vcsserver/http_main.py +++ b/vcsserver/http_main.py @@ -329,7 +329,7 @@ class HTTPApplication(object): self.config.add_view(self.handle_vcs_exception, context=Exception) self.config.add_tween( - 'vcsserver.tweens.RequestWrapperTween', + 'vcsserver.tweens.request_wrapper.RequestWrapperTween', ) def wsgi_app(self): diff --git a/vcsserver/tweens/__init__.py b/vcsserver/tweens/__init__.py new file mode 100644 --- /dev/null +++ b/vcsserver/tweens/__init__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +# Copyright (C) 2016-2019 RhodeCode GmbH +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License, version 3 +# (only), as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# This program is dual-licensed. If you wish to learn more about the +# RhodeCode Enterprise Edition, including its added features, Support services, +# and proprietary license terms, please see https://rhodecode.com/licenses/ diff --git a/vcsserver/tweens.py b/vcsserver/tweens/request_wrapper.py rename from vcsserver/tweens.py rename to vcsserver/tweens/request_wrapper.py --- a/vcsserver/tweens.py +++ b/vcsserver/tweens/request_wrapper.py @@ -32,6 +32,10 @@ def get_access_path(request): return environ.get('PATH_INFO') +def get_user_agent(environ): + return environ.get('HTTP_USER_AGENT') + + class RequestWrapperTween(object): def __init__(self, handler, registry): self.handler = handler @@ -45,14 +49,16 @@ class RequestWrapperTween(object): response = self.handler(request) finally: end = time.time() - - log.info('IP: %s Request to path: `%s` time: %.4fs', - '127.0.0.1', safe_str(get_access_path(request)), end - start) + total = end - start + log.info( + 'IP: %s %s Request to %s time: %.4fs [%s]', + '127.0.0.1', request.environ.get('REQUEST_METHOD'), + safe_str(get_access_path(request)), total, get_user_agent(request.environ)) return response def includeme(config): config.add_tween( - 'vcsserver.tweens.RequestWrapperTween', + 'vcsserver.tweens.request_wrapper.RequestWrapperTween', )