##// END OF EJS Templates
request-wrapper: show version for rhodecode in logs.
marcink -
r3926:229a84ce default
parent child Browse files
Show More
@@ -1,60 +1,61 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2016-2019 RhodeCode GmbH
3 # Copyright (C) 2016-2019 RhodeCode GmbH
4 #
4 #
5 # This program is free software: you can redistribute it and/or modify
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
7 # (only), as published by the Free Software Foundation.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU Affero General Public License
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
16 #
17 # This program is dual-licensed. If you wish to learn more about the
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21 import gc
22 import time
21 import time
23 import logging
22 import logging
24
23
24 import rhodecode
25 from rhodecode.lib.base import get_ip_addr, get_access_path, get_user_agent
25 from rhodecode.lib.base import get_ip_addr, get_access_path, get_user_agent
26 from rhodecode.lib.utils2 import safe_str
26 from rhodecode.lib.utils2 import safe_str
27
27
28
28
29 log = logging.getLogger(__name__)
29 log = logging.getLogger(__name__)
30
30
31
31
32 class RequestWrapperTween(object):
32 class RequestWrapperTween(object):
33 def __init__(self, handler, registry):
33 def __init__(self, handler, registry):
34 self.handler = handler
34 self.handler = handler
35 self.registry = registry
35 self.registry = registry
36
36
37 # one-time configuration code goes here
37 # one-time configuration code goes here
38
38
39 def __call__(self, request):
39 def __call__(self, request):
40 start = time.time()
40 start = time.time()
41 try:
41 try:
42 response = self.handler(request)
42 response = self.handler(request)
43 finally:
43 finally:
44 end = time.time()
44 end = time.time()
45 total = end - start
45 total = end - start
46 count = request.request_count()
46 count = request.request_count()
47 _ver_ = rhodecode.__version__
47 log.info(
48 log.info(
48 'Req[%4s] IP: %s %s Request to %s time: %.4fs [%s]',
49 'Req[%4s] IP: %s %s Request to %s time: %.4fs [%s], RhodeCode %s',
49 count, get_ip_addr(request.environ), request.environ.get('REQUEST_METHOD'),
50 count, get_ip_addr(request.environ), request.environ.get('REQUEST_METHOD'),
50 safe_str(get_access_path(request.environ)), total,
51 safe_str(get_access_path(request.environ)), total,
51 get_user_agent(request. environ)
52 get_user_agent(request. environ), _ver_
52 )
53 )
53
54
54 return response
55 return response
55
56
56
57
57 def includeme(config):
58 def includeme(config):
58 config.add_tween(
59 config.add_tween(
59 'rhodecode.lib.middleware.request_wrapper.RequestWrapperTween',
60 'rhodecode.lib.middleware.request_wrapper.RequestWrapperTween',
60 )
61 )
General Comments 0
You need to be logged in to leave comments. Login now