jbaiter / gphoto2-cffi

Python bindings for libgphoto2 with an idiomatic API
GNU Lesser General Public License v3.0
38 stars 16 forks source link

Getting some extra debug output from v0.4.1 #24

Open define-private-public opened 7 years ago

define-private-public commented 7 years ago

Thanks for pushing a working version. While My application still works, it's showing a lot of extra debug information on the terminal. For example:

Error during assembling of port list: 'Unspecified error' (-1).
Error during assembling of port list: 'Unspecified error' (-1).
Error during assembling of port list: 'Unspecified error' (-1).
Error during assembling of port list: 'Unspecified error' (-1).
Error during assembling of port list: 'Unspecified error' (-1).
Error during assembling of port list: 'Unspecified error' (-1).
Error during assembling of port list: 'Unspecified error' (-1).
storage 0xffffffff, but handle 0x00000000?
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
PTP_OC 0x9153 receiving resp failed: Camera Not Ready (0xa102)
Error during assembling of port list: 'Unspecified error' (-1).
Error during assembling of port list: 'Unspecified error' (-1).
Error during assembling of port list: 'Unspecified error' (-1).
Error during assembling of port list: 'Unspecified error' (-1).
Error during assembling of port list: 'Unspecified error' (-1).
PTP_OC 0x9152 receiving resp failed: PTP Operation Not Supported (0x2005)
PTP_OC 0x911c receiving resp failed: PTP Device Busy (0x2019)
'ptp_canon_eos_resetuilock (params)' failed: PTP Device Busy (0x2019)

that Error during assembling... message comes about once per second. Since I setup a loop to call (a slightly modified version of) list_cameras(). Is there I way I can suppress this extra info?

jbaiter commented 7 years ago

The new version automatically maps from gphoto2 logging levels to the corresponding Python logging levels: https://github.com/jbaiter/gphoto2-cffi/blob/master/gphoto2cffi/backend.py#L45, https://github.com/jbaiter/gphoto2-cffi/blob/master/gphoto2cffi/backend.py#L75 So it should be enough to use Python's standard logging mechanisms to filter out certain loggers and/or log levels.

define-private-public commented 7 years ago

My preference would be to have logging off by default. Then let the user enable/disable it.

Would it be possible to add some module level variable in backend.py, where _logging_callback() has an if statement in it to see if it should print or ignore the log message? We could then add the functions enable_logging()/disable_logging() to backend.py or the LibraryWrapepr class. I'm a little fuzzy on how module level variable scope work in python.

If that seems okay to you, I can test it out and submit a PR for that.

jbaiter commented 7 years ago

I'm not really a fan of the module-level variable... We could instead set the default logging level for the library to logging.CRITICAL (so that errors and warnings will not be printed by default). If a user wants to see more messages, he can just call e.g. logging.getLogger('libgphoto2').setLevel(logging.ERROR). It should suffice to add LOGGER.setLevel(logging.CRITICAL) at https://github.com/jbaiter/gphoto2-cffi/blob/master/gphoto2cffi/backend.py#L11

define-private-public commented 7 years ago

What about moving the _logging_callback() into the LibraryWrapper class as a static method, put that module level variable in the LibraryWrapper instead, and add a check at the beginning of _logging_callback()?

It gets rid of the module level variable, and since lib should be only instantiated once IIRC, they should be able to do something like:

from gphoto2cffi.backend import lib
lib.logging_enabled = True
define-private-public commented 7 years ago

I also think that CRITICAL should be left for well..., critical errors.

jbaiter commented 7 years ago

Well, it would still be, since the library does not log with CRITICAL at all. The effect of setting that level would be to silence the logger as much as possible by default. Your proposal with the LibraryWrapper looks good, though :-)