Skip to content

Commit

Permalink
logging
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kw123 committed Jul 19, 2023
1 parent bfad3e3 commit 4f59056
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion uniFiAP.indigoPlugin/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>PluginVersion</key>
<string>2022.42.387</string>
<string>2022.42.388</string>
<key>ServerApiVersion</key>
<string>3.0</string>
<key>IwsApiVersion</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ in actions you can setup most of the config as as well as get snapshots
<Label>Show DEBUG section........................................................:</Label>
</Field>

<Field id="showLoginTest" type="checkbox" > <Label> show logging test at startup:</Label> </Field>
<Field id="debugLogic" type="checkbox" visibleBindingId="debugOn" visibleBindingValue="true" > <Label>... (1) Logic:</Label> </Field>
<Field id="debugLog" type="checkbox" visibleBindingId="debugOn" visibleBindingValue="true" > <Label>... (2) logMessages:</Label> </Field>
<Field id="debugLogDetails" type="checkbox" visibleBindingId="debugOn" visibleBindingValue="true" > <Label>... (3) ... Details:</Label> </Field>
Expand Down
28 changes: 16 additions & 12 deletions uniFiAP.indigoPlugin/Contents/Server Plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
"debugSpecial": False,
"debugDictFile": False,
"debugall": False,
"showLoginTest": True,
"do_cProfile": "on/off/print",
"rebootUnifiDeviceOnError": True,
"restartListenerEvery": "999999999",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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]))
Expand Down Expand Up @@ -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))


Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion uniFiAP.indigoPlugin/Contents/changeLog.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 4f59056

Please sign in to comment.