From 2806c438a9b73d7421217a63eaa21feecf589d66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkay=20=C3=9Cr=C3=BCn?= Date: Wed, 26 Apr 2023 19:23:06 +0200 Subject: [PATCH] Restructure loggers --- controller.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/controller.py b/controller.py index cff08c1..ec16f0d 100755 --- a/controller.py +++ b/controller.py @@ -23,6 +23,7 @@ from pathlib import Path import pickle import subprocess +import sys import time import pandas as pd @@ -627,6 +628,26 @@ def process_arguments(args): return parguments +def init_logging(): + logging_level = logging.INFO + handler_list = [] + + stream_handler = logging.StreamHandler(sys.stdout) + stream_handler.setLevel(logging.INFO) + handler_list.append(stream_handler) + + if args.debug: + file_handler = logging.FileHandler("log.txt") + handler_list.append(file_handler) + logging_level = logging.DEBUG + + logging.basicConfig( + format="%(asctime)s - %(name)s - %(levelname)s : %(message)s", + level=logging_level, + handlers=handler_list, + ) + + if __name__ == "__main__": """ Main function to programm @@ -637,13 +658,7 @@ def process_arguments(args): parguments = process_arguments(args) - logging_level = logging.INFO - if args.debug: - logging_level = logging.DEBUG - logging.basicConfig( - format="%(asctime)s - %(name)s - %(levelname)s : %(message)s", - level=logging_level, - ) + init_logging() controller( args.hdf5file, # hdf5path