-
Notifications
You must be signed in to change notification settings - Fork 0
/
imports.py
55 lines (42 loc) · 1.88 KB
/
imports.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
import colorlog
import inspect # TODO: when performance hits, replace with sys
import os
handler = colorlog.StreamHandler()
handler.setFormatter(colorlog.ColoredFormatter(
"[%(asctime)s.%(msecs)03d][TID: %(threadName)-10s : %(log_color)s%(levelname)-8s]%(reset)s %(blue)s%(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
reset=True,
log_colors={
'DEBUG' : 'cyan',
'INFO' : 'green',
'WARNING' : 'yellow',
'ERROR' : 'red',
'CRITICAL' : 'red,bg_white',
},
secondary_log_colors={},
style='%'))
logger = colorlog.getLogger('logger') # setup one global logger and filter by TID
logger.addHandler(handler)
def logDebug(message):
func = inspect.currentframe().f_back.f_code
logger.debug("[%s::%s] %s" % (os.path.basename(func.co_filename), func.co_name, message))
def logInfo(message):
func = inspect.currentframe().f_back.f_code
logger.info("[%s::%s] %s" % (os.path.basename(func.co_filename), func.co_name, message)) # file name is good enough
def logWarning(message):
func = inspect.currentframe().f_back.f_code
logger.warning("[%s::%s] %s" % (os.path.basename(func.co_filename), func.co_name, message))
def logError(message):
func = inspect.currentframe().f_back.f_code
logger.error("[%s::%s] %s" % (os.path.basename(func.co_filename), func.co_name, message))
def logCritical(message):
func = inspect.currentframe().f_back.f_code
logger.critical("[%s::%s] %s" % (os.path.basename(func.co_filename), func.co_name, message))
# universal sensor data structure (could be done most efficiently TODO:)
class SensorData():
def __init__(self, sensor_group, sensor_name, sensor_type, time, value):
self.grp = sensor_group
self.name = sensor_name
self.type = sensor_type
self.time = time
self.val = value