-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig_logger.py
57 lines (41 loc) · 1.24 KB
/
config_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
import logging, os
import userConfig
def memoize(function):
""" decorator for caching results """
memo = {}
def wrapper(*args):
if args in memo:
return memo[args]
else:
rv = function(*args)
memo[args] = rv
return rv
return wrapper
#only call once !
@memoize
def do_config():
logger = logging.getLogger('de.mineway.emzed')
logger.setLevel(logging.DEBUG)
# create file handler which logs even debug messages
op = os.path
try:
os.mkdir("logs")
except:
pass
logPath = userConfig.getEmzedFolder()
if not os.path.exists(logPath):
os.makedirs(logPath)
fh = logging.FileHandler(os.path.join(logPath, "emzed.log"))
fh.setLevel(logging.DEBUG)
# create console handler with a higher log level
ch = logging.StreamHandler()
ch.setLevel(logging.WARN)
# create formatter and add it to the handlers
formatter = logging.Formatter('%(asctime)s - %(process)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
fh.setFormatter(formatter)
# add the handlers to logger
logger.addHandler(ch)
logger.addHandler(fh)
__builtins__["LLL"] = logger
logger.debug("start logging")