diff --git a/devices/statistics_writer/statistics_writer.py b/devices/statistics_writer/statistics_writer.py index 0758e319f216281b23ed3c646cdcf24e936282d2..a013cb779b758b8e5256aba23e1ac0ff9a24e9d7 100644 --- a/devices/statistics_writer/statistics_writer.py +++ b/devices/statistics_writer/statistics_writer.py @@ -24,10 +24,7 @@ __all__ = ["statistics_writer"] class statistics_writer: - def __init__(self, new_file_time_interval, file_location, statistics_mode, debug_mode=False): - if debug_mode: - logger.setLevel(logging.DEBUG) - logger.debug("Setting loglevel to DEBUG") + def __init__(self, new_file_time_interval, file_location, statistics_mode): # all variables that deal with the SST matrix that's currently being decoded self.current_matrix = None @@ -187,3 +184,4 @@ class statistics_writer: self.write_matrix() finally: self.file.close() + logger.debug(f"{self.file} closed") diff --git a/devices/statistics_writer/tcp_hdf5_writer.py b/devices/statistics_writer/tcp_hdf5_writer.py index 352e43a03f6074dfc4c11f816637dfc88bc72d55..8d290e293e2db82fa3e12e071e7dda4d6077ea40 100644 --- a/devices/statistics_writer/tcp_hdf5_writer.py +++ b/devices/statistics_writer/tcp_hdf5_writer.py @@ -5,6 +5,9 @@ from statistics_writer import statistics_writer import sys import signal +import logging +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger("statistics_writer") parser = argparse.ArgumentParser(description='Arguments to configure the TCP connection and writer mode') parser.add_argument('--address', type=str, help='the address to connect to') @@ -35,11 +38,15 @@ if __name__ == "__main__": mode = args.mode debug = args.debug + if debug: + logger.setLevel(logging.DEBUG) + logger.debug("Setting loglevel to DEBUG") + # creates the TCP receiver that is given to the writer receiver = tcp_receiver(address, port) # create the writer - writer = statistics_writer(new_file_time_interval=interval, file_location=location, statistics_mode=mode, debug_mode=debug) + writer = statistics_writer(new_file_time_interval=interval, file_location=location, statistics_mode=mode) # start looping try: diff --git a/devices/statistics_writer/test/test_server.py b/devices/statistics_writer/test/test_server.py index c59aa7d68d18040b3d9ee34b940929d9f11db6c0..eec9ec3eed992b03ee809ca37de012bad43bd213 100644 --- a/devices/statistics_writer/test/test_server.py +++ b/devices/statistics_writer/test/test_server.py @@ -39,14 +39,14 @@ while True: conn, addr = s.accept() with conn: - logger.debug('Connected by: ', addr) + logger.debug(f'Connected by: {addr}') while True: time.sleep(INTERVAL) conn.sendall(data) except Exception as e: - logger.warning(f"Exception occured: {e}" ) - + logger.warning(f"Exception occurred: {e}") + # just do 2 interrupt within a second to quit the program time.sleep(1)