From b5b6227fee59993bcf8d129e4498ea1cf41c268a Mon Sep 17 00:00:00 2001 From: sashacmc Date: Wed, 27 Nov 2019 18:41:32 +0100 Subject: [PATCH] log_file config option added --- config.py | 1 + default.cfg | 3 +++ server.py | 11 ++++++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/config.py b/config.py index bc6967b..2e5146e 100755 --- a/config.py +++ b/config.py @@ -32,6 +32,7 @@ class Config(object): 'remote_drive_reg': 'sd[d-z][0-9]', 'out_path': '/mnt/multimedia/NEW/', 'in_path': '', + 'log_file': '/var/log/photo-importer-server.log', } } diff --git a/default.cfg b/default.cfg index 5d5e7e1..ebe15ea 100644 --- a/default.cfg +++ b/default.cfg @@ -47,3 +47,6 @@ out_path = /mnt/multimedia/NEW/ # fixed input path in_path = + +# log file +log_file = /var/log/photo-importer-server.log diff --git a/server.py b/server.py index 8f07300..9e71de8 100755 --- a/server.py +++ b/server.py @@ -126,7 +126,7 @@ class PhotoImporterHandler(http.server.BaseHTTPRequestHandler): try: dev = params['d'][0] - except: + except Exception: dev = '' result = None @@ -334,7 +334,7 @@ class PhotoImporterServer(http.server.HTTPServer): def args_parse(): parser = argparse.ArgumentParser() parser.add_argument('-c', '--config', help='Config file') - parser.add_argument('-l', '--logfile', help='Log file', default='slog.txt') + parser.add_argument('-l', '--logfile', help='Log file') return parser.parse_args() @@ -343,7 +343,12 @@ def main(): cfg = config.Config(args.config) - log.initLogger(args.logfile) + if args.logfile: + logfile = args.logfile + else: + logfile = cfg['server']['log_file'] + + log.initLogger(logfile) try: server = PhotoImporterServer(cfg)