From f9756a71ce01a9369feb6937501c3f19e7af6b0e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 15 Jan 2018 15:53:32 +0100 Subject: [PATCH] Add commandline arguments to enable verbose mode Create a logger hierarchy, that way we only need to set the root logger to DEBUG and the rest goes along with it. --- tuhi.py | 15 ++++++++++++++- tuhi/ble.py | 3 +-- tuhi/dbusserver.py | 3 +-- tuhi/wacom.py | 3 +-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/tuhi.py b/tuhi.py index fe2d5bd..555f707 100755 --- a/tuhi.py +++ b/tuhi.py @@ -11,6 +11,7 @@ # GNU General Public License for more details. # +import argparse import json import logging import sys @@ -20,7 +21,8 @@ from tuhi.dbusserver import TuhiDBusServer from tuhi.ble import BlueZDeviceManager from tuhi.wacom import WacomDevice, Stroke -logging.basicConfig(level=logging.DEBUG) +logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s', + level=logging.INFO) logger = logging.getLogger('tuhi') WACOM_COMPANY_ID = 0x4755 @@ -158,6 +160,17 @@ class Tuhi(GObject.Object): def main(args): + desc = "Daemon to extract the pen stroke data from Wacom SmartPad devices" + parser = argparse.ArgumentParser(description=desc) + parser.add_argument('-v', '--verbose', + help='Show some debugging informations', + action='store_true', + default=False) + + ns = parser.parse_args(args[1:]) + if ns.verbose: + logger.setLevel(logging.DEBUG) + Tuhi() try: GObject.MainLoop().run() diff --git a/tuhi/ble.py b/tuhi/ble.py index 5d417dc..47cd2c9 100755 --- a/tuhi/ble.py +++ b/tuhi/ble.py @@ -13,8 +13,7 @@ import logging from gi.repository import GObject, Gio -logging.basicConfig(level=logging.DEBUG) -logger = logging.getLogger('ble') +logger = logging.getLogger('tuhi.ble') ORG_BLUEZ_GATTCHARACTERISTIC1 = 'org.bluez.GattCharacteristic1' ORG_BLUEZ_GATTSERVICE1 = 'org.bluez.GattService1' diff --git a/tuhi/dbusserver.py b/tuhi/dbusserver.py index ed1ee2b..7ec8b56 100755 --- a/tuhi/dbusserver.py +++ b/tuhi/dbusserver.py @@ -15,8 +15,7 @@ import logging from gi.repository import GObject, Gio, GLib -logging.basicConfig(level=logging.DEBUG) -logger = logging.getLogger('dbus') +logger = logging.getLogger('tuhi.dbus') INTROSPECTION_XML = """ diff --git a/tuhi/wacom.py b/tuhi/wacom.py index 0aeb37c..9987836 100644 --- a/tuhi/wacom.py +++ b/tuhi/wacom.py @@ -18,8 +18,7 @@ import threading import time from gi.repository import GObject -logging.basicConfig(level=logging.DEBUG) -logger = logging.getLogger('wacom') +logger = logging.getLogger('tuhi.wacom') WACOM_COMPANY_ID = 0x4755 NORDIC_UART_SERVICE_UUID = '6e400001-b5a3-f393-e0a9-e50e24dcca9e'