logging in gi.repository import
- From: Robert Schroll <rschroll gmail com>
- To: python-hackers-list gnome org
- Subject: logging in gi.repository import
- Date: Mon, 05 Nov 2012 17:53:06 -0300
Hi all,
Briefly: Why are import errors from gi.repository logged with
logging.error? Isn't the ImportError enough of a clue that something
went wrong?
More detailed: I have an Python program that uses the Notify library,
through pyGObject, as an optional dependency. I do the import something
like this:
>>> try:
... from gi.repository import Notify
... except ImportError:
... Notify = None
If a user has pyGObject and Notify installed, it works fine. If they
don't have pyGObject, it works fine. But if they have pyGObject but not
Notify, they get an error message:
ERROR:root:Could not find any typelib for Notify
even though the program is working correctly. This message, I believe,
is from the logging.error() call in importer.py.
Now I can work around it in my case by adding
>>> import logging
>>> logging.disable(logging.ERROR)
before trying to import from gi.repository. But if I were using the
logging module in my program, I'd have to do a more complicated dance to
turn the logging back on after the import. This seems silly. If this
logging really is important, there should be a custom Logger object in
gi.repository that I can adjust myself. But since the logging message
is immediately followed by an ImportError, it seems completely redundant
to me.
If there's an easier way to suppress this message that I've missed,
please point it out. Otherwise, please consider removing the logging.
Thanks,
Robert
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]