-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
68 lines (54 loc) · 1.75 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
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
from logging import FileHandler
from logging import Formatter
from logging import NOTSET
from logging import StreamHandler
import os
import sys
from holoscope.config import ConfigLoader
from holoscope.core import Holoscope
FORMAT = "[%(asctime)s] [%(levelname)s][%(module)s][%(funcName)s]: %(message)s"
log = logging.getLogger(__name__)
def lambda_handler(event, context):
cl = ConfigLoader()
config = cl.config
logging.basicConfig(
level=(config.general.loglevel).upper(),
format="[{asctime}] [{levelname}][{module}][{funcName}]: {message}",
style='{',
stream=sys.stdout,
force=True
)
holoscope = Holoscope(config)
holoscope.run()
def set_stream_handler(loglevel):
stream_handler = StreamHandler()
stream_handler.setLevel(loglevel)
stream_handler.setFormatter(
Formatter(FORMAT)
)
return stream_handler
def set_file_handler(logdir, logfile, loglevel):
if not os.path.isdir(logdir):
os.makedirs(logdir, exist_ok=True)
file_handler = FileHandler(f"{logdir}/{logfile}")
file_handler.setLevel(loglevel)
file_handler.setFormatter(
Formatter(FORMAT)
)
return file_handler
if __name__ == '__main__':
cl = ConfigLoader()
cnf = cl.config
stream_handler = set_stream_handler(cnf.general.loglevel)
file_handler = set_file_handler(cnf.general.logdir,
cnf.general.logfile,
cnf.general.loglevel)
logging.basicConfig(level=NOTSET, handlers=[stream_handler, file_handler])
logging.basicConfig(
handlers=[stream_handler, file_handler]
)
holoscope = Holoscope(cnf)
holoscope.run()