-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.py
36 lines (27 loc) · 1.17 KB
/
common.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
import logging
def set_attr_from_dict(obj, dictionary):
"""set object attribute k = v from a dictionary's k, v for all dict items"""
for k,v in dictionary.items():
setattr(obj, k, v)
def get_module_logger(modulename = 'experiment', loglevel = logging.INFO):
if modulename.startswith('smp_graphs'):
modulename = '.'.join(modulename.split('.')[1:])
# print "get_module_logger: modulename = %s" % (modulename, )
# create logger
logger = logging.getLogger(modulename)
logger.setLevel(loglevel)
# create console handler and set level to debug
ch = logging.StreamHandler()
ch.setLevel(loglevel)
# create formatter
# formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
formatter = logging.Formatter('%(levelname)8s: %(name)20s: %(message)s')
# formatter = logging.Formatter('{levelname:8}s: %(name)20s: %(message)s')
# formatter = logging.Formatter('%(name)s: %(levelname)s: %(message)s')
# add formatter to ch
ch.setFormatter(formatter)
# add ch to logger
logger.addHandler(ch)
# suppress double log output
logger.propagate = False
return logger