-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.py
executable file
·68 lines (54 loc) · 2.62 KB
/
main.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 -*-
from __future__ import unicode_literals
from utils.config_helper import ConfigHelper
from process import process
import logging.config
import logging
import argparse
import os
__author__ = "Liu Lihao"
def set_logging(error_log_config_file_path, error_log_folder_path, error_log_level):
if not os.path.exists(error_log_folder_path):
os.makedirs(error_log_folder_path)
# set log file path and level
# log_config = ConfigHelper.load_config(os.path.join(os.path.dirname(__file__), "conf", "log.yaml"))
log_config = ConfigHelper.load_config(error_log_config_file_path)
log_config["handlers"]["file_handler"]["filename"] = os.path.join(error_log_folder_path, "logs")
log_config["handlers"]["file_handler"]["level"] = error_log_level
logging.config.dictConfig(log_config)
def main():
# first read parameters
parser = argparse.ArgumentParser()
log_parameter = parser.add_argument_group("Error log parameters", "Parameters are used for error logging.")
log_parameter.add_argument("--error_log_config_file_path",
default="./conf/log.yaml",
help="The Error log config file path.")
log_parameter.add_argument("--error_log_folder_path",
default="./logs/error_logs/",
help="The error log output position.")
log_parameter.add_argument("--error_log_level",
default="DEBUG",
choices=["DEBUG", "INFO", "ERROR", "WARNING", "CRITICAL"],
help="The error log level.")
program_parameter = parser.add_argument_group("Initialization parameters",
"Parameters are used for initialize program.")
program_parameter.add_argument("--args_config_file_path",
default="./conf/args.yaml",
help="The args config path which will be to used to init program.")
args = parser.parse_args()
# second set logging and get logger
# print args.error_log_config_file_path, args.error_log_folder_path, args.error_log_level
set_logging(args.error_log_config_file_path, args.error_log_folder_path, args.error_log_level)
logger = logging.getLogger()
# third start program
logger.info("Begin program")
try:
# print args.args_config_file_path
process(args.args_config_file_path)
except Exception as e:
logger.error(e.message)
raise
logger.info("Program end")
if __name__ == '__main__':
main()