From 329e5a66ed05f15da41e9de0f72f7cf08186ddb7 Mon Sep 17 00:00:00 2001 From: thijs snijder <snijder@astron.nl> Date: Wed, 22 Sep 2021 10:39:36 +0200 Subject: [PATCH] small fixes --- devices/statistics_writer/statistics_writer.py | 6 ++---- devices/statistics_writer/tcp_hdf5_writer.py | 9 ++++++++- devices/statistics_writer/test/test_server.py | 6 +++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/devices/statistics_writer/statistics_writer.py b/devices/statistics_writer/statistics_writer.py index 0758e319f..a013cb779 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 352e43a03..8d290e293 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 c59aa7d68..eec9ec3ee 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) -- GitLab