Python logging used by Indigo

Posted on
Fri Apr 22, 2016 9:55 am
jay (support) offline
Site Admin
User avatar
Posts: 14648
Joined: Mar 19, 2008
Location: Austin, Texas

Python logging used by Indigo

[NOTE] This note is for plugin developers, not plugin users. The change should be made by the developer/maintainer of the plugin.

As of Indigo 6.1.8, we're now using the standard Python logging facility. We made this change in preparation for a complete overhaul of plugin logging in Indigo 7. This change has introduced some logging issues. Several plugins began logging odd things into the Indigo log. The reason is that libraries used by those plugins are set by default to log at the INFO level, and they contain logging at that level. We log everything at the INFO level to the Indigo log, so now there is more stuff showing up.

The primary library we're seeing is the requests library, and more specifically the urllib3 library that's installed with it. That library liberally uses INFO level logging throughout. We believe that pattern, for a library, is a poor design, but it is what it is. Fortunately, there's a simple way to fix it. Once you import the library, you can adjust the level thusly:

Code: Select all
logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("urllib3").setLevel(logging.WARNING)


You can use it for either - the current crop of unneeded logging is specifically in the urllib3 library, so you can just adjust that. You can use any of the standard logging levels of course. Anything below that level will not be logged. The default for both is logging.INFO, but setting it to a higher level will solve the problem.

See this stackoverflow post for a more complete discussion.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Apr 23, 2016 9:31 am
bkmar1192 offline
Posts: 274
Joined: Sep 12, 2015

Re: Python logging used by Indigo

It is not clear what am I suppose to do with this information. Do I need to change something - I tried running that code as trigger but it didn't seem to change anything. Is this a change that needs to happen in the plugin itself or can I do it globally? My log is filling up with messages.

Posted on
Sat Apr 23, 2016 9:42 am
autolog offline
Posts: 2386
Joined: Sep 10, 2013
Location: West Sussex

Re: Python logging used by Indigo

bkmar1192 wrote:
It is not clear what am I suppose to do with this information. Do I need to change something - I tried running that code as trigger but it didn't seem to change anything. Is this a change that needs to happen in the plugin itself or can I do it globally? My log is filling up with messages.

The instructions above are for the plugin authors who need to implement the change as noted above.

Which plugin are you using that is filling the log?

Posted on
Sat Apr 23, 2016 11:40 am
fishmg01 offline
Posts: 27
Joined: Sep 16, 2013

Re: Python logging used by Indigo

I am getting what seems to be an identical problem with endless error messages in the log for the Hue Lights Plugin.

Hue Lights Starting new HTTP connection (1): 10.0.1.184
Hue Lights Starting new HTTP connection (1): 10.0.1.184
Hue Lights Starting new HTTP connection (1): 10.0.1.184
Hue Lights Starting new HTTP connection (1): 10.0.1.184
Etc Etc....

It sounds like the author of the plugin is going to have to implement the fix ? Is that correct?

Posted on
Sat Apr 23, 2016 12:03 pm
autolog offline
Posts: 2386
Joined: Sep 10, 2013
Location: West Sussex

Re: Python logging used by Indigo

Yes - suggest you post regarding your issue in the Hue Plugin forum as the author monitors that forum. :)

There is already a thread here :)

Posted on
Wed May 04, 2016 9:13 pm
RogueProeliator offline
User avatar
Posts: 2032
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: Python logging used by Indigo

Code: Select all
logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("urllib3").setLevel(logging.WARNING)

Okay, does it matter where (what module) calls this code? It doesn't seem to work for me... but perhaps I am doing it somewhere/someway that is out of scope? Requests is included with the plugin itself and is called from a module in a subdirectory...

Server Plugin -> RPFramework -> requests

I've never used python logging and will definitely read up on it, but if anyone knows off-hand a gotcha in that scenario, please let me know...

Adam

Posted on
Wed May 04, 2016 9:31 pm
RogueProeliator offline
User avatar
Posts: 2032
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: Python logging used by Indigo

Okay, as often happens, figured it out after posting... if any others run across this, it appears the logger is named as it were loaded in the module that imported it - so in my case I had to do:
Code: Select all
logging.getLogger("RPFramework.requests").setLevel(logging.WARNING)
logging.getLogger("RPFramework.requests.packages.urllib3").setLevel(logging.WARNING)

with the RPFramework being the module/subdirectory of the path to the requests module.

Adam

Posted on
Thu May 05, 2016 9:49 am
jay (support) offline
Site Admin
User avatar
Posts: 14648
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python logging used by Indigo

Python logging is incredibly flexible/powerful. But, as is always the case, that flexibility comes at the price of complexity. I think the tradeoff is worth it though. We may not have everything about our approach completely nailed, but we're monitoring and will make changes as necessary.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue May 10, 2016 8:29 pm
matt (support) offline
Site Admin
User avatar
Posts: 18609
Joined: Jan 27, 2003
Location: Texas

Re: Python logging used by Indigo

We've addressed this problem in v6.1.9 that was just posted. Plugins (or modules used by plugins) that request the default logger will no longer log to the Event Log window.

Image

Posted on
Wed May 11, 2016 5:05 am
autolog offline
Posts: 2386
Joined: Sep 10, 2013
Location: West Sussex

Re: Python logging used by Indigo

Just to confirm I have switched my plugins' debugging back to setlevel(logging.INFO) and all is working OK again in 6.1.9 :D

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest