Python logging used by Indigo

Discuss the Indigo Plugin SDK and developing Indigo plugins here.
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Python logging used by Indigo

Post by jay (support) »

[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
bkmar1192
Posts: 274
Joined: Sat Sep 12, 2015 11:23 am

Re: Python logging used by Indigo

Post by bkmar1192 »

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.
autolog
Posts: 4077
Joined: Tue Sep 10, 2013 3:07 am
Location: West Sussex, UK
Contact:

Re: Python logging used by Indigo

Post by autolog »

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?
fishmg01
Posts: 32
Joined: Mon Sep 16, 2013 3:58 pm

Re: Python logging used by Indigo

Post by fishmg01 »

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?
autolog
Posts: 4077
Joined: Tue Sep 10, 2013 3:07 am
Location: West Sussex, UK
Contact:

Re: Python logging used by Indigo

Post by autolog »

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

There is already a thread here :)
User avatar
RogueProeliator
Posts: 2538
Joined: Tue Nov 13, 2012 3:54 pm
Location: Baton Rouge, LA

Re: Python logging used by Indigo

Post by RogueProeliator »

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
User avatar
RogueProeliator
Posts: 2538
Joined: Tue Nov 13, 2012 3:54 pm
Location: Baton Rouge, LA

Re: Python logging used by Indigo

Post by RogueProeliator »

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
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: Python logging used by Indigo

Post by jay (support) »

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
User avatar
matt (support)
Site Admin
Posts: 21542
Joined: Mon Jan 27, 2003 1:17 pm
Location: Texas
Contact:

Re: Python logging used by Indigo

Post by matt (support) »

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
autolog
Posts: 4077
Joined: Tue Sep 10, 2013 3:07 am
Location: West Sussex, UK
Contact:

Re: Python logging used by Indigo

Post by autolog »

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
howartp
Posts: 4559
Joined: Thu Jan 09, 2014 4:43 pm
Location: West Yorkshire, UK

Re: Python logging used by Indigo

Post by howartp »

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
User avatar
FlyingDiver
Posts: 7830
Joined: Sat Jun 07, 2014 10:36 am
Location: Southwest Florida, USA

Re: Python logging used by Indigo

Post by FlyingDiver »

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
howartp
Posts: 4559
Joined: Thu Jan 09, 2014 4:43 pm
Location: West Yorkshire, UK

Re: Python logging used by Indigo

Post by howartp »

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!
Post Reply

Return to “Plugin SDK and Development”