-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
executable file
·57 lines (44 loc) · 1.26 KB
/
run.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
#!/usr/bin/env python3
import os
import sys
import asyncio
import logging
import typing
from pyhocon import ConfigFactory
from app.server import Server
def log_level_from_string(log_level: typing.Optional[str]):
log_level = log_level.lower()
log_levels = {
"debug": logging.DEBUG,
"info": logging.INFO,
"warning": logging.WARNING,
"error": logging.ERROR,
}
# if log level is debug set flask to debug as well
if log_level == "debug":
os.environ['FLASK_ENV'] = "development"
if log_level in log_levels:
return log_levels[log_level]
else:
return log_levels["info"]
def setup_logging(config: dict):
logging.basicConfig(
level=log_level_from_string(config.get("log_level", None)),
format="[%(asctime)s] [%(levelname)-8s] -- %(message)s",
stream=sys.stdout
)
async def main():
server = Server(config, logging=logging)
try:
await server.start()
except Exception as err:
logging.error(str(err), exc_info=True)
finally:
await server.stop()
if __name__ == "__main__":
config = ConfigFactory.parse_file("config.conf")
setup_logging(config)
try:
asyncio.run(main())
except KeyboardInterrupt:
pass