-
Notifications
You must be signed in to change notification settings - Fork 4
/
stat_logger.py
45 lines (38 loc) · 1.09 KB
/
stat_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
#!/usr/bin/env python
# encoding: utf-8
"""
This service logs stat messages from Navitia 2 to file in JSON format
"""
import sys
import argparse
import yaml
from exceptions import KeyboardInterrupt
import logging
from stat_logger.daemon import Daemon
def main():
"""
main: ce charge d'interpreter les parametres de la ligne de commande
"""
parser = argparse.ArgumentParser(description="This service logs stat messages from Navitia 2 to file in JSON format")
parser.add_argument('config_file', type=str)
config_file = ""
try:
args = parser.parse_args()
config_file = args.config_file
except argparse.ArgumentTypeError:
print("Bad usage, learn how to use me with %s -h" % sys.argv[0])
sys.exit(1)
# Configuration parsing
with file(config_file, 'r') as stream:
config = yaml.load(stream)
try:
daemon = Daemon(config)
daemon.run()
except KeyboardInterrupt:
pass
except:
logging.exception('fatal error')
sys.exit(2)
sys.exit(0)
if __name__ == "__main__":
main()