-
Notifications
You must be signed in to change notification settings - Fork 12
/
log_execute_console.py
30 lines (23 loc) · 973 Bytes
/
log_execute_console.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
from openerp_proxy.service.object import ObjectService
from contextlib import contextmanager
import time
@contextmanager
def timeit_context(name):
startTime = time.time()
yield
elapsedTime = time.time() - startTime
print('[{}] finished in {} ms'.format(name, int(elapsedTime * 1000)))
LOG_SIMPLE = False
class ObjectServiceLog(ObjectService):
""" Simply logs all calls to ``execute`` method of `object` service
to console (displying all arguments).
If module level variable ``LOG_SIMPLE`` set to True,then
only simple lines like 'Execute [<obj>, <method>] will be displayed
"""
def execute(self, obj, method, *args, **kwargs):
if LOG_SIMPLE:
msg = "Execute [%s, %s]" % (obj, method)
else:
msg = "Execute [%s, %s] (%s, %s)" % (obj, method, args, kwargs)
with timeit_context(msg):
return super(ObjectServiceLog, self).execute(obj, method, *args, **kwargs)