Merge lp:~javier.collado/utah/battery-measurements-logging into lp:utah
Status: | Merged |
---|---|
Approved by: | Javier Collado |
Approved revision: | 832 |
Merged at revision: | 832 |
Proposed branch: | lp:~javier.collado/utah/battery-measurements-logging |
Merge into: | lp:utah |
Diff against target: |
22 lines (+5/-1) 1 file modified
utah/client/battery.py (+5/-1) |
To merge this branch: | bzr merge lp:~javier.collado/utah/battery-measurements-logging |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
UTAH Dev | Pending | ||
Review via email: mp+153123@code.launchpad.net |
Description of the change
As explained in the commit message:
-----
The battery module creates a singleton object at import time to take care of
gathering the data related to all battery measurements. Unfortunately, if a
logging method is used, logging.basicConfig is called with default arguments.
Later, UTAHs configure logging function believes logging is already configured
and as a results logging ends up being wrongly configured.
To fix this, this change delays the computation done at import time and does
them the first time the object is used which is later than logging has been
configured.
----
Note that this merge request is needed by the changes in:
https:/
for them to work properly with regard to logging.
Here's my concern (and I'm not sure if its worth considering):
If someone ever did something innocent like add a "logging.info" to _Battery.__init__, then this bug will come back. It seems like the real bug is at the end of the file:
battery = _Battery()
I wonder if we should change that to be something like:
_inst = None
def get_battery():
if not inst:
_inst = _Battery()
return _inst
then you'd have to refactor who uses this, so maybe its overkill