Python logging used by Indigo

Posted on
Fri Apr 22, 2016 9:55 am
jay (support) offline
Site Admin
User avatar
Posts: 18200
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: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

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: 32
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: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

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: 2501
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: 2501
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: 18200
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: 21411
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: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

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

Posted on
Sat Aug 03, 2019 9:06 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Python logging used by Indigo

I haven't yet implemented any loggers() - i'm still using self.debugLog() and indigo.server.log()

Until I get myself sorted, is there any way in imported libraries such as Tesla to log things to either debugLog() or indigo.server.log()?

plugin.py
import indigo
import teslajson
self.debugLog("Started connecting")
connection = teslajson.Connection(self.pluginPrefs['username'],self.pluginPrefs['password'])
self.debugLog("Finished connecting")

teslajson.py
class Connection(object):
def __init__(self,email='',password=''):
HOWDOI.debugLog("opening baseurl")
tesla_client = self.__open2("/raw/pS7Z6yyP", baseurl="http://pastebin.com") #This is TimDorr's version, without id and api
HOWDOI.indigo.server.log("retrieved TeslaClient")
self.oauth = {"grant_type" : "password","client_id" : tesla_client[0],"client_secret" : tesla_client[1],"email" : email,"password" : password }
self.expiration = 0 # force refresh
HOWDOI.errorLog("Happy Birthday To %s".format(tesla_client[0])
self.vehicles = [Vehicle(v, self) for v in self.get('vehicles')['response']]


At the moment i'm havinng to throw(ValueException "HappyBirthdayToYou %s".format(tesla_client[0])) just to test what's happening ... which isn't right!

Peter

Posted on
Sat Aug 03, 2019 9:24 am
FlyingDiver online
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python logging used by Indigo

Put this at the top
Code: Select all
import logging
logger = logging.getLogger("Plugin.TeslaLibrary")

Put this wherever
Code: Select all
logger.debug(u"Got here with {}".format(something))       

I think that'll work. If the library is class based, you might need to use self.logger instead of a global variable.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sun Nov 10, 2019 10:16 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Python logging used by Indigo

FlyingDiver wrote:
Put this at the top
Code: Select all
import logging
logger = logging.getLogger("Plugin.TeslaLibrary")

Put this wherever
Code: Select all
logger.debug(u"Got here with {}".format(something))       

I think that'll work. If the library is class based, you might need to use self.logger instead of a global variable.

Necro reply, but thanks - that's working great!

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 6 guests