From 5de6c692fb17dcb27e3b67452226884ebdae55c9 Mon Sep 17 00:00:00 2001 From: Nils <> Date: Tue, 16 Jun 2020 21:46:12 +0200 Subject: [PATCH] Better logging in nsmclient --- template/qtgui/nsmclient.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/template/qtgui/nsmclient.py b/template/qtgui/nsmclient.py index 512eeae..04a08d1 100644 --- a/template/qtgui/nsmclient.py +++ b/template/qtgui/nsmclient.py @@ -269,15 +269,15 @@ class NSMClient(object): global logger logger = logging.getLogger(prettyName) - logger.info("import") + logger.info("import") if loggingLevel == "info" or loggingLevel == 20: logging.basicConfig(level=logging.INFO) #development logger.info("Starting PyNSM2 Client with logging level INFO. Switch to 'error' for a release!") #the NSM name is not ready yet so we just use the pretty name elif loggingLevel == "error" or loggingLevel == 40: logging.basicConfig(level=logging.ERROR) #production else: - raise ValueError("Unknown logging level: {}. Choose 'info' or 'error'".format(loggingLevel)) - + logging.warning("Unknown logging level: {}. Choose 'info' or 'error'".format(loggingLevel)) + logging.basicConfig(level=logging.INFO) #development #given parameters, self.prettyName = prettyName #keep this consistent! Settle for one name. @@ -302,8 +302,7 @@ class NSMClient(object): } #self.discardReactions = set(["/nsm/client/session_is_loaded"]) self.discardReactions = set() - - + #Networking and Init self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) #internet, udp self.sock.bind(('', 0)) #pick a free port on localhost. @@ -324,7 +323,9 @@ class NSMClient(object): self.ourClientId = None # the "file extension" of ourClientNameUnderNSM self.isVisible = None #set in announceGuiVisibility self.saveStatus = True # true is clean. false means we need saving. + self.announceOurselves() + assert self.serverFeatures, self.serverFeatures assert self.sessionName, self.sessionName assert self.ourPath, self.ourPath @@ -334,7 +335,9 @@ class NSMClient(object): #After this point the host must include self.reactToMessage in its event loop #We assume we are save at startup. - self.announceSaveStatus(isClean = True) + self.announceSaveStatus(isClean = True) + + logger.info("NSMClient client init complete. Going into listening mode.") def reactToMessage(self): @@ -418,6 +421,8 @@ class NSMClient(object): else: return "" + logger.info("Sending our NSM-announce message") + announce = _OutgoingMessage("/nsm/server/announce") announce.add_arg(self.prettyName) #s:application_name announce.add_arg(buildClientFeaturesString()) #s:capabilities @@ -490,10 +495,12 @@ class NSMClient(object): self.announceSaveStatus(isClean = True) - def _sessionIsLoadedCallback(self, msg): + def _sessionIsLoadedCallback(self, msg): if self.sessionIsLoadedCallback: - logger.info("Telling our client that the session has finished loading") + logger.info("Received 'Session is Loaded'. Our client supports it. Forwarding message...") self.sessionIsLoadedCallback() + else: + logger.info("Received 'Session is Loaded'. Our client does not support it, which is the default. Discarding message...") def sigtermHandler(self, signal, frame): """Wait for the user to quit the program