forked from rijdendetreinen/rdt-infoplus-dvs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdvs_util.py
50 lines (40 loc) · 1.36 KB
/
dvs_util.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
"""
Generieke utility functies.
"""
import os
import sys
import yaml
import logging
import logging.config
def load_config(config_file_path='config/config.yaml'):
"""
Setup logging configuration
"""
if os.path.exists(config_file_path):
try:
with open(config_file_path, 'r') as config_file:
config = yaml.load(config_file.read())
except (yaml.parser.ParserError, yaml.parser.ScannerError) as exception:
print "YAML fout in config file: %s" % exception
sys.exit(1)
except Exception as exception:
print "Fout in configuratiebestand. Foutmelding: %s" % exception
sys.exit(1)
else:
print "Configuratiebestand '%s' niet aanwezig" % config_file_path
sys.exit(1)
return config
def setup_logging(config):
"""
Setup logging configuration
"""
# Check of er een logger configuratie is opgegeven:
if 'logging' in config and 'log_config' in config['logging']:
log_config_file = config['logging']['log_config']
# Stel logger in adhv config:
if os.path.exists(log_config_file):
with open(log_config_file, 'r') as config_file:
log_config = yaml.load(config_file.read())
logging.config.dictConfig(log_config)
return
logging.basicConfig(level=logging.INFO)