Open define-private-public opened 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.
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.
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
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
I also think that CRITICAL
should be left for well..., critical errors.
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 :-)
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:
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?