From 4f59056d8fac523a47c115447b3af931b28fa238 Mon Sep 17 00:00:00 2001 From: kw123 Date: Wed, 19 Jul 2023 17:30:43 +0200 Subject: [PATCH] logging changes in V2022.42.388@ 2023-07-20 ================== 1. added config option in general section to set request - curl timeout to any value >=1 sec 2. made error logging more verbose 3. added option to supress test logging at startup, default is log, set in config under section debug 4. fixed print parameters requests timeout was not properly formatted --- uniFiAP.indigoPlugin/Contents/Info.plist | 2 +- .../Contents/Server Plugin/PluginConfig.xml | 1 + .../Contents/Server Plugin/plugin.py | 28 +++++++++++-------- uniFiAP.indigoPlugin/Contents/changeLog.txt | 3 +- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/uniFiAP.indigoPlugin/Contents/Info.plist b/uniFiAP.indigoPlugin/Contents/Info.plist index 02dc226..c76bf8e 100755 --- a/uniFiAP.indigoPlugin/Contents/Info.plist +++ b/uniFiAP.indigoPlugin/Contents/Info.plist @@ -3,7 +3,7 @@ PluginVersion - 2022.42.387 + 2022.42.388 ServerApiVersion 3.0 IwsApiVersion diff --git a/uniFiAP.indigoPlugin/Contents/Server Plugin/PluginConfig.xml b/uniFiAP.indigoPlugin/Contents/Server Plugin/PluginConfig.xml index ce8c68a..1be007d 100755 --- a/uniFiAP.indigoPlugin/Contents/Server Plugin/PluginConfig.xml +++ b/uniFiAP.indigoPlugin/Contents/Server Plugin/PluginConfig.xml @@ -740,6 +740,7 @@ in actions you can setup most of the config as as well as get snapshots + diff --git a/uniFiAP.indigoPlugin/Contents/Server Plugin/plugin.py b/uniFiAP.indigoPlugin/Contents/Server Plugin/plugin.py index a3f246e..08e0c90 100755 --- a/uniFiAP.indigoPlugin/Contents/Server Plugin/plugin.py +++ b/uniFiAP.indigoPlugin/Contents/Server Plugin/plugin.py @@ -239,6 +239,7 @@ "debugSpecial": False, "debugDictFile": False, "debugall": False, + "showLoginTest": True, "do_cProfile": "on/off/print", "rebootUnifiDeviceOnError": True, "restartListenerEvery": "999999999", @@ -304,6 +305,7 @@ def __init__(self, pluginId, pluginDisplayName, pluginVersion, pluginPrefs): self.indigoPreferencesPluginDir = self.getInstallFolderPath+"Preferences/Plugins/"+self.pluginId+"/" self.indigoPluginDirOld = self.userIndigoDir + self.pluginShortName+"/" self.PluginLogFile = indigo.server.getLogsFolderPath(pluginId=self.pluginId) +"/plugin.log" + self.showLoginTest = pluginPrefs.get('showLoginTest',True) formats= { logging.THREADDEBUG: "%(asctime)s %(msg)s", logging.DEBUG: "%(asctime)s %(msg)s", @@ -333,15 +335,16 @@ def __init__(self, pluginId, pluginDisplayName, pluginVersion, pluginPrefs): self.indiLOG.log(10,"plugin.py {}".format(self.pathToPlugin)) self.indiLOG.log(10,"indigo {}".format(self.indigoRootPath)) self.indiLOG.log(20,"detailed logging {}".format(self.PluginLogFile)) - self.indiLOG.log(20,"testing logging levels, for info only: ") - self.indiLOG.log( 0,"logger enabled for 0 ==> TEST ONLY ") - self.indiLOG.log( 5,"logger enabled for THREADDEBUG ==> TEST ONLY ") - self.indiLOG.log(10,"logger enabled for DEBUG ==> TEST ONLY ") - self.indiLOG.log(20,"logger enabled for INFO ==> TEST ONLY ") - self.indiLOG.log(30,"logger enabled for WARNING ==> TEST ONLY ") - self.indiLOG.log(40,"logger enabled for ERROR ==> TEST ONLY ") - self.indiLOG.log(50,"logger enabled for CRITICAL ==> TEST ONLY ") - self.indiLOG.log(10,"Plugin short Name {}".format(self.pluginShortName)) + if self.showLoginTest: + self.indiLOG.log(20,"testing logging levels, for info only: ") + self.indiLOG.log( 0,"logger enabled for 0 ==> TEST ONLY ") + self.indiLOG.log( 5,"logger enabled for THREADDEBUG ==> TEST ONLY ") + self.indiLOG.log(10,"logger enabled for DEBUG ==> TEST ONLY ") + self.indiLOG.log(20,"logger enabled for INFO ==> TEST ONLY ") + self.indiLOG.log(30,"logger enabled for WARNING ==> TEST ONLY ") + self.indiLOG.log(40,"logger enabled for ERROR ==> TEST ONLY ") + self.indiLOG.log(50,"logger enabled for CRITICAL ==> TEST ONLY ") + self.indiLOG.log(10,"Plugin short Name {}".format(self.pluginShortName)) self.indiLOG.log(10,"my PID {}".format(self.myPID)) self.indiLOG.log(10,"Achitecture {}".format(platform.platform())) self.indiLOG.log(10,"OS {}".format(platform.mac_ver()[0])) @@ -918,6 +921,7 @@ def setDebugFromPrefs(self, theDict, writeToLog=True): self.debugLevel = [] for d in _debugAreas: if theDict.get("debug"+d, False): self.debugLevel.append(d) + self.showLoginTest = self.pluginPrefs.get("showLoginTest", True) if writeToLog: self.indiLOG.log(20,"debug settings :{} ".format(self.debugLevel)) @@ -1682,7 +1686,7 @@ def printConfigMenu(self, valuesDict=None, typeId=""): out += "\nsleep in main loop ".ljust(40) + "{:.0f} [sec]".format(self.loopSleep) out += "\nuse curl or request".ljust(40) + self.requestOrcurl out += "\ncurl path".ljust(40) + self.curlPath - out += "\ncurl/requests timeout".ljust(40) + self.requestTimeout + out += "\ncurl/requests timeout".ljust(40) + "{:.0f} [sec]".format(self.requestTimeout) out += "\ncpu used since restart: ".ljust(40) + self.getCPU(self.myPID) out += "\n" out += "\n====== used in ssh userid@switch-IP, AP-IP, USG-IP to get DB dump and listen to events" @@ -5273,12 +5277,12 @@ def executeCMDOnController(self, dataSEND={}, pageString="",jsonAction="returnDa try: loginDict = json.loads(resp.text) except Exception as e: if "{}".format(e).find("None") == -1: self.indiLOG.log(40,"", exc_info=True) - self.indiLOG.log(40,"UNIFI executeCMDOnController error no json object: (wrong UID/passwd, ip number?{}) ...>>{}<<".format(self.unifiCloudKeyIP, resp.text)) + self.indiLOG.log(30,"UNIFI executeCMDOnController error no json object: (wrong UID/passwd, ip number?{}) ...>>{}<<".format(self.unifiCloudKeyIP, resp.text)) self.executeCMDOnControllerReset(wait=True, calledFrom="executeCMDOnController-login json") continue if resp.status_code != requests.codes.ok: - self.indiLOG.log(40,"UNIFI executeCMDOnController login url:{}\ngives, ok not found or status_code:{} not in [{}]\n error: {}\n".format(url,resp.status_code, requests.codes.ok, resp.text[0:300]) ) + self.indiLOG.log(30,"UNIFI executeCMDOnController login url:{}\ngives, ok not found or status_code:{} not in [{}]\n error: {}\n".format(url,resp.status_code, requests.codes.ok, resp.text[0:300]) ) self.executeCMDOnControllerReset(wait=True, calledFrom="executeCMDOnController-login ret code not ok") continue if 'X-CSRF-Token' in resp.headers: diff --git a/uniFiAP.indigoPlugin/Contents/changeLog.txt b/uniFiAP.indigoPlugin/Contents/changeLog.txt index ba26ec3..c2f7bec 100755 --- a/uniFiAP.indigoPlugin/Contents/changeLog.txt +++ b/uniFiAP.indigoPlugin/Contents/changeLog.txt @@ -1,8 +1,9 @@ -changes in V2022.42.387@ 2023-07-20 +changes in V2022.42.388@ 2023-07-20 ================== 1. added config option in general section to set request - curl timeout to any value >=1 sec 2. made error logging more verbose +3. added option to supress test logging at startup, default is log, set in config under section debug changes in V2022.42.385@ 2023-07-19