make sure all debug and info loggings are if-guarded
This commit is contained in:
parent
ca2f5f927c
commit
39534d11dd
|
@ -343,8 +343,9 @@ def request(handle, devnumber, request_id, *params):
|
|||
# _log.error("(%s) device %d error on request {%04X}: unknown device", handle, devnumber, request_id)
|
||||
# raise NoSuchDevice(number=devnumber, request=request_id)
|
||||
|
||||
_log.debug("(%s) device 0x%02X error on request {%04X}: %d = %s",
|
||||
handle, devnumber, request_id, error, _hidpp10.ERROR[error])
|
||||
if _log.isEnabledFor(_DEBUG):
|
||||
_log.debug("(%s) device 0x%02X error on request {%04X}: %d = %s",
|
||||
handle, devnumber, request_id, error, _hidpp10.ERROR[error])
|
||||
return
|
||||
|
||||
if reply_data[:1] == b'\xFF' and reply_data[1:3] == request_data[:2]:
|
||||
|
|
|
@ -337,7 +337,8 @@ def get_firmware(device):
|
|||
fw_info = _FirmwareInfo(FIRMWARE_KIND.Other, '', '', None)
|
||||
|
||||
fw.append(fw_info)
|
||||
# _log.debug("device %d firmware %s", devnumber, fw_info)
|
||||
# if _log.isEnabledFor(_DEBUG):
|
||||
# _log.debug("device %d firmware %s", devnumber, fw_info)
|
||||
return tuple(fw)
|
||||
|
||||
|
||||
|
@ -351,7 +352,8 @@ def get_kind(device):
|
|||
kind = feature_request(device, FEATURE.DEVICE_NAME, 0x20)
|
||||
if kind:
|
||||
kind = ord(kind[:1])
|
||||
# _log.debug("device %d type %d = %s", devnumber, kind, DEVICE_KIND[kind])
|
||||
# if _log.isEnabledFor(_DEBUG):
|
||||
# _log.debug("device %d type %d = %s", devnumber, kind, DEVICE_KIND[kind])
|
||||
return DEVICE_KIND[kind]
|
||||
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ try:
|
|||
except ImportError:
|
||||
from queue import Queue as _Queue
|
||||
|
||||
from logging import getLogger, DEBUG as _DEBUG
|
||||
from logging import getLogger, DEBUG as _DEBUG, INFO as _INFO
|
||||
_log = getLogger('LUR.listener')
|
||||
del getLogger
|
||||
|
||||
|
@ -49,7 +49,8 @@ class _ThreadedHandle(object):
|
|||
if handle is None:
|
||||
_log.error("%r failed to open new handle", self)
|
||||
else:
|
||||
# _log.debug("%r opened new handle %d", self, handle)
|
||||
# if _log.isEnabledFor(_DEBUG):
|
||||
# _log.debug("%r opened new handle %d", self, handle)
|
||||
self._local.handle = handle
|
||||
self._handles.append(handle)
|
||||
return handle
|
||||
|
@ -135,7 +136,8 @@ class EventsListener(_threading.Thread):
|
|||
self.receiver.handle = _ThreadedHandle(self, self.receiver.path, self.receiver.handle)
|
||||
# get the right low-level handle for this thead
|
||||
ihandle = int(self.receiver.handle)
|
||||
_log.info("started with %s (%d)", self.receiver, ihandle)
|
||||
if _log.isEnabledFor(_INFO):
|
||||
_log.info("started with %s (%d)", self.receiver, ihandle)
|
||||
|
||||
self.has_started()
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
from logging import getLogger, DEBUG as _DEBUG
|
||||
from logging import getLogger, DEBUG as _DEBUG, INFO as _INFO
|
||||
_log = getLogger('LUR.notifications')
|
||||
del getLogger
|
||||
|
||||
|
@ -46,7 +46,8 @@ def _process_receiver_notification(receiver, status, n):
|
|||
if n.sub_id == 0x4A:
|
||||
status.lock_open = bool(n.address & 0x01)
|
||||
reason = 'pairing lock is ' + ('open' if status.lock_open else 'closed')
|
||||
_log.info("%s: %s", receiver, reason)
|
||||
if _log.isEnabledFor(_INFO):
|
||||
_log.info("%s: %s", receiver, reason)
|
||||
|
||||
status[_K.ERROR] = None
|
||||
if status.lock_open:
|
||||
|
@ -110,7 +111,8 @@ def _process_hidpp10_custom_notification(device, status, n):
|
|||
if n.sub_id == _R.illumination:
|
||||
# message layout: 10 ix 17("address") <??> <?> <??> <light level 1=off..5=max>
|
||||
# TODO anything we can do with this?
|
||||
_log.info("illumination event: %s", n)
|
||||
if _log.isEnabledFor(_INFO):
|
||||
_log.info("illumination event: %s", n)
|
||||
return True
|
||||
|
||||
_log.warn("%s: unrecognized %s", device, n)
|
||||
|
@ -171,7 +173,7 @@ def _process_hidpp10_notification(device, status, n):
|
|||
reason = str(status) or 'powered on'
|
||||
status.changed(active=True, alert=_ALERT.NOTIFICATION, reason=reason)
|
||||
else:
|
||||
_log.info("%s: unknown %s", device, n)
|
||||
_log.warn("%s: unknown %s", device, n)
|
||||
return True
|
||||
|
||||
_log.warn("%s: unrecognized %s", device, n)
|
||||
|
@ -184,15 +186,16 @@ def _process_feature_notification(device, status, n, feature):
|
|||
battery_status = ord(n.data[1:2])
|
||||
status.set_battery_info(discharge, _hidpp20.BATTERY_STATUS[battery_status])
|
||||
else:
|
||||
_log.info("%s: unknown BATTERY %s", device, n)
|
||||
_log.warn("%s: unknown BATTERY %s", device, n)
|
||||
return True
|
||||
|
||||
# TODO: what are REPROG_CONTROLS_V{2,3}?
|
||||
if feature == _F.REPROG_CONTROLS:
|
||||
if n.address == 0x00:
|
||||
_log.info("%s: reprogrammable key: %s", device, n)
|
||||
if _log.isEnabledFor(_INFO):
|
||||
_log.info("%s: reprogrammable key: %s", device, n)
|
||||
else:
|
||||
_log.info("%s: unknown REPROGRAMMABLE KEYS %s", device, n)
|
||||
_log.warn("%s: unknown REPROGRAMMABLE KEYS %s", device, n)
|
||||
return True
|
||||
|
||||
if feature == _F.WIRELESS_DEVICE_STATUS:
|
||||
|
@ -202,9 +205,9 @@ def _process_feature_notification(device, status, n, feature):
|
|||
if n.data[0:3] == b'\x01\x01\x01':
|
||||
status.changed(active=True, alert=_ALERT.NOTIFICATION, reason='powered on')
|
||||
else:
|
||||
_log.info("%s: unknown WIRELESS %s", device, n)
|
||||
_log.warn("%s: unknown WIRELESS %s", device, n)
|
||||
else:
|
||||
_log.info("%s: unknown WIRELESS %s", device, n)
|
||||
_log.warn("%s: unknown WIRELESS %s", device, n)
|
||||
return True
|
||||
|
||||
if feature == _F.SOLAR_DASHBOARD:
|
||||
|
@ -222,7 +225,8 @@ def _process_feature_notification(device, status, n, feature):
|
|||
status[_K.BATTERY_CHARGING] = lux > 200
|
||||
status.changed(active=True)
|
||||
elif n.address == 0x20:
|
||||
_log.debug("%s: Light Check button pressed", device)
|
||||
if _log.isEnabledFor(_DEBUG):
|
||||
_log.debug("%s: Light Check button pressed", device)
|
||||
status.changed(alert=_ALERT.SHOW_WINDOW)
|
||||
# first cancel any reporting
|
||||
# device.feature_request(_F.SOLAR_DASHBOARD)
|
||||
|
@ -231,21 +235,23 @@ def _process_feature_notification(device, status, n, feature):
|
|||
reports_period = 2 # seconds
|
||||
device.feature_request(_F.SOLAR_DASHBOARD, 0x00, reports_count, reports_period)
|
||||
else:
|
||||
_log.info("%s: unknown SOLAR CHAGE %s", device, n)
|
||||
_log.warn("%s: unknown SOLAR CHAGE %s", device, n)
|
||||
else:
|
||||
_log.warn("%s: SOLAR CHARGE not GOOD? %s", device, n)
|
||||
return True
|
||||
|
||||
if feature == _F.TOUCHMOUSE_RAW_POINTS:
|
||||
if n.address == 0x00:
|
||||
_log.info("%s: TOUCH MOUSE points %s", device, n)
|
||||
if _log.isEnabledFor(_INFO):
|
||||
_log.info("%s: TOUCH MOUSE points %s", device, n)
|
||||
elif n.address == 0x10:
|
||||
touch = ord(n.data[:1])
|
||||
button_down = bool(touch & 0x02)
|
||||
mouse_lifted = bool(touch & 0x01)
|
||||
_log.info("%s: TOUCH MOUSE status: button_down=%s mouse_lifted=%s", device, button_down, mouse_lifted)
|
||||
if _log.isEnabledFor(_INFO):
|
||||
_log.info("%s: TOUCH MOUSE status: button_down=%s mouse_lifted=%s", device, button_down, mouse_lifted)
|
||||
else:
|
||||
_log.warn("%s: unknown TOUCH MOUSE %s", device, n)
|
||||
return True
|
||||
|
||||
_log.info("%s: unrecognized %s for feature %s (index %02X)", device, n, feature, n.sub_id)
|
||||
_log.warn("%s: unrecognized %s for feature %s (index %02X)", device, n, feature, n.sub_id)
|
||||
|
|
|
@ -7,7 +7,7 @@ from __future__ import absolute_import, division, print_function, unicode_litera
|
|||
import errno as _errno
|
||||
# from weakref import proxy as _proxy
|
||||
|
||||
from logging import getLogger
|
||||
from logging import getLogger, INFO as _INFO
|
||||
_log = getLogger('LUR.receiver')
|
||||
del getLogger
|
||||
|
||||
|
@ -60,7 +60,8 @@ class PairedDevice(object):
|
|||
self._polling_rate = None
|
||||
self._power_switch = None
|
||||
|
||||
# _log.debug("new PairedDevice(%s, %s, %s)", receiver, number, link_notification)
|
||||
# if _log.isEnabledFor(_DEBUG):
|
||||
# _log.debug("new PairedDevice(%s, %s, %s)", receiver, number, link_notification)
|
||||
|
||||
if link_notification is not None:
|
||||
self.online = bool(ord(link_notification.data[0:1]) & 0x40)
|
||||
|
@ -123,7 +124,8 @@ class PairedDevice(object):
|
|||
# if the ping failed, the peripheral is (almost) certainly offline
|
||||
self.online = self._protocol is not None
|
||||
|
||||
# _log.debug("device %d protocol %s", self.number, self._protocol)
|
||||
# if _log.isEnabledFor(_DEBUG):
|
||||
# _log.debug("device %d protocol %s", self.number, self._protocol)
|
||||
return self._protocol or 0
|
||||
|
||||
@property
|
||||
|
@ -132,7 +134,8 @@ class PairedDevice(object):
|
|||
codename = self.receiver.read_register(_R.receiver_info, 0x40 + self.number - 1)
|
||||
if codename:
|
||||
self._codename = codename[2:].rstrip(b'\x00').decode('utf-8')
|
||||
# _log.debug("device %d codename %s", self.number, self._codename)
|
||||
# if _log.isEnabledFor(_DEBUG):
|
||||
# _log.debug("device %d codename %s", self.number, self._codename)
|
||||
else:
|
||||
self._codename = '? (%s)' % self.wpid
|
||||
return self._codename
|
||||
|
@ -250,7 +253,8 @@ class PairedDevice(object):
|
|||
|
||||
flag_bits = _hidpp10.get_notification_flags(self)
|
||||
flag_names = None if flag_bits is None else tuple(_hidpp10.NOTIFICATION_FLAG.flag_names(flag_bits))
|
||||
_log.info("%s: device notifications %s %s", self, 'enabled' if enable else 'disabled', flag_names)
|
||||
if _log.isEnabledFor(_INFO):
|
||||
_log.info("%s: device notifications %s %s", self, 'enabled' if enable else 'disabled', flag_names)
|
||||
return flag_bits if ok else None
|
||||
|
||||
def request(self, request_id, *params):
|
||||
|
@ -364,7 +368,8 @@ class Receiver(object):
|
|||
|
||||
flag_bits = _hidpp10.get_notification_flags(self)
|
||||
flag_names = None if flag_bits is None else tuple(_hidpp10.NOTIFICATION_FLAG.flag_names(flag_bits))
|
||||
_log.info("%s: receiver notifications %s => %s", self, 'enabled' if enable else 'disabled', flag_names)
|
||||
if _log.isEnabledFor(_INFO):
|
||||
_log.info("%s: receiver notifications %s => %s", self, 'enabled' if enable else 'disabled', flag_names)
|
||||
return flag_bits
|
||||
|
||||
def notify_devices(self):
|
||||
|
@ -383,7 +388,8 @@ class Receiver(object):
|
|||
try:
|
||||
dev = PairedDevice(self, number, notification)
|
||||
assert dev.wpid
|
||||
_log.info("%s: found new device %d (%s)", self, number, dev.wpid)
|
||||
if _log.isEnabledFor(_INFO):
|
||||
_log.info("%s: found new device %d (%s)", self, number, dev.wpid)
|
||||
self._devices[number] = dev
|
||||
return dev
|
||||
except _base.NoSuchDevice:
|
||||
|
|
|
@ -6,7 +6,7 @@ import os as _os
|
|||
import os.path as _path
|
||||
from json import load as _json_load, dump as _json_save
|
||||
|
||||
from logging import getLogger, DEBUG as _DEBUG
|
||||
from logging import getLogger, DEBUG as _DEBUG, INFO as _INFO
|
||||
_log = getLogger(__name__)
|
||||
del getLogger
|
||||
|
||||
|
@ -61,7 +61,8 @@ def save():
|
|||
with open(_file_path, 'w') as config_file:
|
||||
_json_save(_configuration, config_file, skipkeys=True, indent=2, sort_keys=True)
|
||||
|
||||
_log.info("saved %s to %s", _configuration, _file_path)
|
||||
if _log.isEnabledFor(_INFO):
|
||||
_log.info("saved %s to %s", _configuration, _file_path)
|
||||
return True
|
||||
except:
|
||||
_log.error("failed to save to %s", _file_path)
|
||||
|
|
|
@ -154,7 +154,8 @@ class ReceiverListener(_listener.EventsListener):
|
|||
|
||||
def _notifications_handler(self, n):
|
||||
assert self.receiver
|
||||
# _log.debug("%s: handling %s", self.receiver, n)
|
||||
# if _log.isEnabledFor(_DEBUG):
|
||||
# _log.debug("%s: handling %s", self.receiver, n)
|
||||
if n.devnumber == 0xFF:
|
||||
# a receiver notification
|
||||
_notifications.process(self.receiver, n)
|
||||
|
|
|
@ -34,7 +34,8 @@ def _look_for_application_icons():
|
|||
from os import environ as _environ
|
||||
|
||||
import sys as _sys
|
||||
_log.debug("sys.path[0] = %s", _sys.path[0])
|
||||
if _log.isEnabledFor(_DEBUG):
|
||||
_log.debug("sys.path[0] = %s", _sys.path[0])
|
||||
prefix_share = _path.normpath(_path.join(_path.realpath(_sys.path[0]), '..'))
|
||||
src_share = _path.normpath(_path.join(_path.realpath(_sys.path[0]), '..', 'share'))
|
||||
local_share = _environ.get('XDG_DATA_HOME', _path.expanduser('~/.local/share'))
|
||||
|
@ -56,7 +57,8 @@ def _look_for_application_icons():
|
|||
_default_theme = Gtk.IconTheme.get_default()
|
||||
for p in _look_for_application_icons():
|
||||
_default_theme.prepend_search_path(p)
|
||||
_log.debug("icon theme paths: %s", _default_theme.get_search_path())
|
||||
if _log.isEnabledFor(_DEBUG):
|
||||
_log.debug("icon theme paths: %s", _default_theme.get_search_path())
|
||||
|
||||
#
|
||||
#
|
||||
|
@ -69,7 +71,9 @@ _has_gnome_icons = _default_theme.has_icon('battery-caution-charging') and \
|
|||
_default_theme.has_icon('battery-full-charged')
|
||||
_has_elementary_icons = _default_theme.has_icon('battery-020-charging')
|
||||
|
||||
_log.debug("detected icon sets: gpm %s, oxygen %s, gnome %s, elementary %s", _has_gpm_icons, _has_oxygen_icons, _has_gnome_icons, _has_elementary_icons)
|
||||
if _log.isEnabledFor(_DEBUG):
|
||||
_log.debug("detected icon sets: gpm %s, oxygen %s, gnome %s, elementary %s",
|
||||
_has_gpm_icons, _has_oxygen_icons, _has_gnome_icons, _has_elementary_icons)
|
||||
if (not _has_gpm_icons and not _has_oxygen_icons and
|
||||
not _has_gnome_icons and not _has_elementary_icons):
|
||||
_log.warning("failed to detect a known icon set")
|
||||
|
@ -186,7 +190,8 @@ def icon_file(name, size=_LARGE_SIZE):
|
|||
if _default_theme.has_icon(name):
|
||||
theme_icon = _default_theme.lookup_icon(name, size, 0)
|
||||
file_name = theme_icon.get_filename()
|
||||
_log.debug("icon %s(%d) => %s", name, size, file_name)
|
||||
# if _log.isEnabledFor(_DEBUG):
|
||||
# _log.debug("icon %s(%d) => %s", name, size, file_name)
|
||||
return file_name
|
||||
|
||||
_log.warn("icon %s(%d) not found in current theme", name, size)
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
from logging import getLogger, DEBUG as _DEBUG
|
||||
from logging import getLogger, DEBUG as _DEBUG, INFO as _INFO
|
||||
_log = getLogger(__name__)
|
||||
del getLogger
|
||||
|
||||
|
@ -54,8 +54,8 @@ try:
|
|||
# raise ImportError
|
||||
from gi.repository import AppIndicator3
|
||||
|
||||
_log.info("using AppIndicator3")
|
||||
|
||||
if _log.isEnabledFor(_INFO):
|
||||
_log.info("using AppIndicator3")
|
||||
|
||||
_last_scroll = 0
|
||||
def _scroll(ind, _, direction):
|
||||
|
@ -184,7 +184,8 @@ try:
|
|||
|
||||
except ImportError:
|
||||
|
||||
_log.info("using StatusIcon")
|
||||
if _log.isEnabledFor(_INFO):
|
||||
_log.info("using StatusIcon")
|
||||
|
||||
def _create(menu):
|
||||
icon = Gtk.StatusIcon.new_from_icon_name(_icons.TRAY_INIT)
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
from logging import getLogger
|
||||
from logging import getLogger, INFO as _INFO
|
||||
_log = getLogger(__name__)
|
||||
del getLogger
|
||||
|
||||
|
@ -16,14 +16,16 @@ del getLogger
|
|||
_suspend_callback = None
|
||||
def _suspend():
|
||||
if _suspend_callback:
|
||||
_log.info("received suspend event from UPower")
|
||||
if _log.isEnabledFor(_INFO):
|
||||
_log.info("received suspend event from UPower")
|
||||
_suspend_callback()
|
||||
|
||||
|
||||
_resume_callback = None
|
||||
def _resume():
|
||||
if _resume_callback:
|
||||
_log.info("received resume event from UPower")
|
||||
if _log.isEnabledFor(_INFO):
|
||||
_log.info("received resume event from UPower")
|
||||
_resume_callback()
|
||||
|
||||
|
||||
|
@ -54,7 +56,8 @@ try:
|
|||
bus.add_signal_receiver(_resume, signal_name='Resuming',
|
||||
dbus_interface=_UPOWER_INTERFACE, bus_name=_UPOWER_BUS)
|
||||
|
||||
_log.info("connected to system dbus, watching for suspend/resume events")
|
||||
if _log.isEnabledFor(_INFO):
|
||||
_log.info("connected to system dbus, watching for suspend/resume events")
|
||||
|
||||
except:
|
||||
# Either:
|
||||
|
|
Loading…
Reference in New Issue