monitorin_log_request: _dispatch is a classmethod

This commit is contained in:
Jordi Riera
2019-02-11 17:46:04 -05:00
parent 1e310e34a8
commit 535c658b70
2 changed files with 17 additions and 14 deletions
+2 -3
View File
@@ -1,11 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Camptocamp SA # Copyright 2016 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
{'name': 'Monitoring: Requests Logging', {'name': 'Monitoring: Requests Logging',
'version': '11.0.1.0.0', 'version': '11.0.2.0.0',
'author': 'Camptocamp,Odoo Community Association (OCA)', 'author': 'Camptocamp,Numigi,Odoo Community Association (OCA)',
'license': 'AGPL-3', 'license': 'AGPL-3',
'category': 'category', 'category': 'category',
'depends': ['base', 'web'], 'depends': ['base', 'web'],
+15 -11
View File
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Camptocamp SA # Copyright 2016 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
@@ -17,26 +16,30 @@ _logger = logging.getLogger('monitoring.http.requests')
class IrHttp(models.AbstractModel): class IrHttp(models.AbstractModel):
_inherit = 'ir.http' _inherit = 'ir.http'
def _dispatch(self): @classmethod
def _dispatch(cls):
begin = time.time() begin = time.time()
response = super(IrHttp, self)._dispatch() response = super(IrHttp, cls)._dispatch()
end = time.time() end = time.time()
if (not self._monitoring_blacklist(http_request) and if (not cls._monitoring_blacklist(http_request) and
self._monitoring_filter(http_request)): cls._monitoring_filter(http_request)):
info = self._monitoring_info(http_request, response, begin, end) info = cls._monitoring_info(http_request, response, begin, end)
self._monitoring_log(info) cls._monitoring_log(info)
return response return response
def _monitoring_blacklist(self, request): @classmethod
def _monitoring_blacklist(cls, request):
path_info = request.httprequest.environ.get('PATH_INFO') path_info = request.httprequest.environ.get('PATH_INFO')
if path_info.startswith('/longpolling/'): if path_info.startswith('/longpolling/'):
return True return True
return False return False
def _monitoring_filter(self, request): @classmethod
def _monitoring_filter(cls, _):
return True return True
def _monitoring_info(self, request, response, begin, end): @classmethod
def _monitoring_info(cls, request, response, begin, end):
path = request.httprequest.environ.get('PATH_INFO') path = request.httprequest.environ.get('PATH_INFO')
info = { info = {
# timing # timing
@@ -75,5 +78,6 @@ class IrHttp(models.AbstractModel):
}) })
return info return info
def _monitoring_log(self, info): @classmethod
def _monitoring_log(cls, info):
_logger.info(json.dumps(info)) _logger.info(json.dumps(info))