This repository has been archived by the owner on May 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
config.py
67 lines (59 loc) · 2.02 KB
/
config.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
67
#encoding: utf-8
import logging
import logging.config
import json
import os.path
logging.basicConfig()
def load_config(cfg_path):
with open(cfg_path, 'r') as f:
return json.loads(f.read())
def config_logger():
# set up logging to file - see previous section for more details
log_path = os.path.join(configuration['data_path'],'log')
logging.config.dictConfig({
'version': 1,
'disable_existing_loggers': False, # this fixes the problem
'formatters': {
'standard': {
'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s'
},
'console': {
'format': '[%(levelname)s] %(message)s'
}
},
'handlers': {
'default': {
'level':'DEBUG',
'class':'logging.StreamHandler',
"formatter": "console",
},
"info_file_handler": {
"class": "logging.handlers.RotatingFileHandler",
"level": "INFO",
"formatter": "standard",
"filename": os.path.join(log_path, 'brickmover.info.log'),
"maxBytes": "10485760",
"backupCount": "20",
"encoding": "utf8"
},
"error_file_handler": {
"class": "logging.handlers.RotatingFileHandler",
"level": "ERROR",
"formatter": "standard",
"filename": os.path.join(log_path, 'brickmover.error.log'),
"maxBytes": "10485760",
"backupCount": "20",
"encoding": "utf8"
},
},
'loggers': {
'': {
'handlers': ['default', 'info_file_handler', 'error_file_handler'],
'level': 'DEBUG',
'propagate': True
}
}
})
cfg_path = os.path.join(os.getenv('HOME'), 'etc/brickmover.conf')
configuration = load_config(cfg_path)
config_logger()