From b947724710b8cf2e4e0244b1b52675579c7bfaf0 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 30 May 2020 15:18:07 +0200 Subject: [PATCH] Scripts API: SuperScanner: add timestamp in log messages --- scriptsapi/superscanner.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/scriptsapi/superscanner.py b/scriptsapi/superscanner.py index 7acc3298c..fbe622029 100644 --- a/scriptsapi/superscanner.py +++ b/scriptsapi/superscanner.py @@ -14,6 +14,7 @@ except ImportError: import _thread as thread import time +from datetime import datetime from optparse import OptionParser import sdrangel @@ -47,6 +48,11 @@ class SuperScannerOptionsError(SuperScannerError): class SuperScannerAPIError(SuperScannerError): pass +# ====================================================================== +def log_with_timestamp(message): + t = datetime.utcnow() + print(f'{t.isoformat()} {message}') + # ====================================================================== def get_input_options(args=None): if args is None: @@ -139,7 +145,7 @@ def on_ws_close(ws): # ====================================================================== def on_ws_open(ws): - print('Starting...') + log_with_timestamp('Starting...') def run(*args): pass thread.start_new_thread(run, ()) @@ -324,12 +330,12 @@ def process_hotspots(scanned_hotspots): channel['usage'] = 2 # mark channel used on this pass channel['frequency'] = channel_frequency set_channel_frequency(channel) - print(f'Channel {channel_index} allocated on frequency {channel_frequency} Hz') + log_with_timestamp(f'Channel {channel_index} allocated on frequency {channel_frequency} Hz') else: fc = hotspot['fc'] if fc not in UNSERVED_FREQUENCIES: UNSERVED_FREQUENCIES.append(fc) - print(f'All channels allocated. Cannot process signal at {fc} Hz') + log_with_timestamp(f'All channels allocated. Cannot process signal at {fc} Hz') # cleanup for channel in CONFIG['channel_info']: if channel['usage'] == 1: # channel unused on this pass @@ -338,7 +344,7 @@ def process_hotspots(scanned_hotspots): fc = channel['frequency'] set_channel_mute(channel) UNSERVED_FREQUENCIES.clear() # at least one channel is able to serve next time - print(f'Released channel {channel_index} on frequency {fc} Hz') + log_with_timestamp(f'Released channel {channel_index} on frequency {fc} Hz') elif channel['usage'] == 2: # channel used on this pass channel['usage'] = 1 # reset usage for next pass