-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathservice_logger.py
97 lines (83 loc) · 3.56 KB
/
service_logger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# -*- coding: utf-8 -*-
##############################################################################
#
# This file is part of service_logger, an Odoo module.
#
# Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>)
#
# service_logger is free software: you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License
# as published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# service_logger 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 Affero General Public License for more details.
#
# You should have received a copy of the
# GNU Affero General Public License
# along with service_logger.
# If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import logging
from openerp import http
from openerp.osv import orm
from openerp.http import request
from openerp.addons.web.controllers.main import DataSet
_logger = logging.getLogger(__name__)
class service_logger(orm.AbstractModel):
_name = 'service.logger'
_description = 'Service logger'
def log_fct(self, cr, uid, model, method, *args, **kw):
"""
Logging function: This function is performing the logging operation
@param model: Object whose values are being changed
@param method: method to log: create, read, write, unlink, action or
workflow action
"""
_logger.info("%s %s.%s %s %s", uid, model, method, args or '',
kw or '')
def log_fct_result(self, cr, uid, model, method, res, *args, **kw):
"""
Logging function result: This function can be used to perform the
logging operation of the function result
@param model: Object whose values are being changed
@param method: method to log: create, read, write, unlink, action or
workflow action
@param res: method return value
"""
pass
def log_fct_exception(self, cr, uid, model, method, ex, *args, **kw):
"""
Logging function exception: This function can be used to perform the
logging operation of an exception raised by the function
@param model: Object whose values are being changed
@param method: method to log: create, read, write, unlink, action or
workflow action
@param ex: exception raised
"""
pass
class LoggerDataSet(DataSet):
def _call_kw(self, model, method, args, kw):
service_logger_obj = request.registry.get('service.logger')
cr = request.cr
uid = request.uid
if service_logger_obj:
service_logger_obj.log_fct(cr, uid, model, method, args, kw)
try:
res = super(LoggerDataSet, self)._call_kw(model, method, args, kw)
if service_logger_obj:
service_logger_obj.log_fct_result(
cr, uid, model, method, res, args, kw)
return res
except Exception, e:
if service_logger_obj:
service_logger_obj.log_fct_exception(
cr, uid, model, method, e, args, kw)
raise
@http.route(['/web/dataset/call_kw', '/web/dataset/call_kw/<path:path>'],
type='json', auth="user")
def call_kw(self, model, method, args, kwargs, path=None):
return self._call_kw(model, method, args, kwargs)