-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscarlett_log.py
66 lines (56 loc) · 1.84 KB
/
scarlett_log.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
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import gi
# gi.require_version('Tracker', '1.0')
# from gi.repository import Tracker
from itertools import chain
import logging
import time
logger = logging.getLogger(__name__)
tabbing = 0
def log(fn):
if logger.getEffectiveLevel() > logging.DEBUG:
return fn
def wrapped(*v, **k):
global tabbing
name = fn.__qualname__
filename = fn.__code__.co_filename.split('/')[-1]
lineno = fn.__code__.co_firstlineno
params = ", ".join(map(repr, chain(v, k.values())))
if 'rateLimitedFunction' not in name:
logger.debug("%s%s(%s)[%s:%s]",
'|' * tabbing, name, params, filename, lineno,)
tabbing += 1
start = time.time()
retval = fn(*v, **k)
elapsed = time.time() - start
tabbing -= 1
elapsed_time = ''
if elapsed > 0.1:
elapsed_time = ', took %02f' % elapsed
if (
elapsed_time or retval is not None
) and 'rateLimitedFunction' not in name:
logger.debug("%s returned %s%s", '|' * tabbing, repr(retval), elapsed_time)
return retval
return wrapped
# class TrackerWrapper:
# class __TrackerWrapper:
# def __init__(self):
# try:
# self.tracker = Tracker.SparqlConnection.get(None)
# except Exception as e:
# from sys import exit
# logger.error("Cannot connect to tracker, error '%s'\Exiting", str(e))
# exit(1)
#
# def __str__(self):
# return repr(self)
# instance = None
#
# def __init__(self):
# if not TrackerWrapper.instance:
# TrackerWrapper.instance = TrackerWrapper.__TrackerWrapper()
#
# def __getattr__(self, name):
# return getattr(self.instance, name)