Forgive me if I'm wrong, and I haven't actually tested this out, but doesn't 
the 
new behaviour mean that if I am using python logging, and I set the logging 
level on my application root logger to INFO (for instance) that I no longer see 
logging from pyusb without an explicit...

logging.getLogger("usb").setLevel(logging.INFO) ?

Isn't this the exact _opposite_ of what libraries are meant to do for logging?

If you are using logging in your app, and you don't want to get logging from a 
library that you are using, I expect the user to turn off logging for that 
library.  At least, that's what _I_ expect.  (it's what log4j/slf4j does, and 
it's also how all of my apps and libraries work.

I personally consider what Chris reports to be "expected behaviour"

Cheers,
Karl P

On 08/29/2011 01:16 PM, Wander Lairson Costa wrote:
> 2011/8/27 chris clark<clac...@gmail.com>:
>> I know pyusb (in svn) is currently not really supported/ready but I have a
>> usability question/observation.
>>
> Although not ready, many people are using it without problems. And I
> am pleasure to support any question in the mailing list.
>
>> If I have a (dumb) example script that uses the "basic" logging settings and
>> pyusb fails to load a backend the OpenUSB load attempt ends up being logged
>> when it too fails, a traceback is also dumped (the script keeps on going).
>>
>> Example script and output
>>
>> ## -------------------- cut here --
>> """List usb devices using basic logging.
>> This shows conflicts with pyusb logging implementation.
>>
>> """
>>
>>
>> import logging
>>
>> do_logging = True  # And demo problem
>> #do_logging = False  # Pick one :)
>>
>> log = logging
>>
>> if do_logging:
>>      log.info('hello from test app, no more logging wil be issued form this
>> script')
>>
>> import usb.core
>> import usb.util
>>
>> import usb.backend.libusb10
>>
>>
>> # Monkey patch libusb10 away, or simply run on a machine without libusb10
>> def fake_get():
>>      return None
>>
>> usb.backend.libusb10.get_backend = fake_get
>>
>> for dev in usb.core.find(find_all=True):
>>      print dev
>> ## -------------------- cut here --
>>
>> ## -------------------- cut here --
>> ERROR:usb.backend.openusb:Error loading OpenUSB backend
>> Traceback (most recent call last):
>>    File "/home/clach04/dev/python/usb/pyusb/trunk/usb/backend/openusb.py",
>> line 598, in get_backend
>>      _lib = _load_library()
>>    File "/home/clach04/dev/python/usb/pyusb/trunk/usb/backend/openusb.py",
>> line 148, in _load_library
>>      raise OSError('USB library could not be found')
>> OSError: USB library could not be found
>> <usb.core.Device object at 0x9d4f84c>
>> <usb.core.Device object at 0x9d4f8cc>
>> <usb.core.Device object at 0x9d4f92c>
>> <usb.core.Device object at 0x9d4f96c>
>> <usb.core.Device object at 0x9d4f9ac>
>> <usb.core.Device object at 0x9d4f9ec>
>> <usb.core.Device object at 0x9d4fa2c>
>> <usb.core.Device object at 0x9d4fa6c>
>> ## -------------------- cut here --
>>
>> is there a way to disable this behavior? I'm guessing this is some debug
>> code that is causing this. There are 2 issues:
>>
>> 1) the back trace that gets dumped out
>> 2) the error gets logged (without logging for the usb.backend.openusb logger
>> being (explictly) turned on by the caller.
>>
>>
>> #2 is probably fixable by explicitly setting a log level (of off) in the
>> pyusb code. I could look into doing that if it would be helpful.
>>
>> The workarounds are:
>>
>> 1) Don't use the basic logger in a user script, e.g. add something like; log
>> = logging.getLogger('mylogger') to the user script
>> 2) use libusb10
>>
>> It isn't a huge issue but a little odd.
>>
>
> The problem is that the default behavior on logging module it to
> dispatch the log handling to the parent when level is set to NOTSET. A
> smarter way to do handling in app is to create your own logger:
>
> log = logging.getLogger('foo')
>
> Whatever, I created a patch to this problem, please test it and report
> the status, so I can commit it to the source tree. Thanks for the bug
> report.
>
>
>
>
>
> ------------------------------------------------------------------------------
> EMC VNX: the world's simplest storage, starting under $10K
> The only unified storage solution that offers unified management
> Up to 160% more powerful than alternatives and 25% more efficient.
> Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev
>
>
>
> _______________________________________________
> pyusb-users mailing list
> pyusb-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/pyusb-users

------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better 
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
_______________________________________________
pyusb-users mailing list
pyusb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyusb-users

Reply via email to