-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.py
More file actions
41 lines (32 loc) · 1.09 KB
/
project.py
File metadata and controls
41 lines (32 loc) · 1.09 KB
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
import argparse
import logging
from configparser import ConfigParser
from source import main
LOG_FORMAT = "%(asctime)s [%(levelname)s][%(filename)s:%(funcName)s] %(message)s"
def parse_args():
parser = argparse.ArgumentParser("Basic config parser")
parser.add_argument(
"--config", dest="config", help="The config file path"
)
return parser.parse_args()
def parse_config(config_path):
config = ConfigParser()
config.read(config_path)
return config
def setup_logging(config):
""" Setup basic root logger """
log_level = config.get("logging", "log_level")
log_path = config.get("logging", "log_path")
handler = logging.FileHandler(log_path)
formatter = logging.Formatter(LOG_FORMAT)
handler.setFormatter(formatter)
logger = logging.getLogger()
logger.setLevel(getattr(logging, log_level.upper()))
logger.addHandler(handler)
if __name__ == "__main__":
args = parse_args()
config = parse_config(args.config)
setup_logging(config)
logging.info("Starting program...")
main.run(config)
logging.info("Exiting program...")