From 7d060aa325e1543e70f95c3e216ea39e0e0e351f Mon Sep 17 00:00:00 2001 From: Athanasius Date: Fri, 24 Jul 2020 21:39:18 +0100 Subject: [PATCH] plugins/inara: Convert to proper logging --- plugins/inara.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/plugins/inara.py b/plugins/inara.py index dcfd5c70..0288076c 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -15,12 +15,10 @@ import tkinter as tk from ttkHyperlinkLabel import HyperlinkLabel import myNotebook as nb +from EDMarketConnector import logger from config import appname, applongname, appversion, config import plug -if __debug__: - from traceback import print_exc - _TIMEOUT = 20 FAKE = ['CQC', 'Training', 'Destination'] # Fake systems that shouldn't be sent to Inara @@ -457,7 +455,7 @@ def journal_entry(cmdr, is_beta, system, station, entry, state): call() except Exception as e: - if __debug__: print_exc() + logger.debug(f'Adding events', exc_info=e) return str(e) # @@ -898,14 +896,15 @@ def worker(): callback(reply) elif status // 100 != 2: # 2xx == OK (maybe with warnings) # Log fatal errors - print('Inara\t%s %s' % (reply['header']['eventStatus'], reply['header'].get('eventStatusText', ''))) - print(json.dumps(data, indent=2, separators = (',', ': '))) + log.warning(f'Inara\t{status} {reply["header"].get("eventStatusText", "")}') + log.debug(f'JSON data:\n{json.dumps(data, indent=2, separators = (",", ": "))}') plug.show_error(_('Error: Inara {MSG}').format(MSG = reply['header'].get('eventStatusText', status))) else: # Log individual errors and warnings for data_event, reply_event in zip(data['events'], reply['events']): if reply_event['eventStatus'] != 200: - print('Inara\t%s %s\t%s' % (reply_event['eventStatus'], reply_event.get('eventStatusText', ''), json.dumps(data_event))) + logger.warning(f'Inara\t{status} {reply_event.get("eventStatusText", "")}') + logger.debug(f'JSON data:\n{json.dumps(data_event)}') if reply_event['eventStatus'] // 100 != 2: plug.show_error(_('Error: Inara {MSG}').format(MSG = '%s, %s' % (data_event['eventName'], reply_event.get('eventStatusText', reply_event['eventStatus'])))) if data_event['eventName'] in ['addCommanderTravelCarrierJump', 'addCommanderTravelDock', 'addCommanderTravelFSDJump', 'setCommanderTravelLocation']: @@ -916,8 +915,8 @@ def worker(): this.system_link.event_generate('<>', when="tail") # calls update_ship in main thread break - except: - if __debug__: print_exc() + except Exceptionas e: + logger.debug(f'Sending events', exc_info=e) retrying += 1 else: if callback: