diff --git a/bumblebee-status b/bumblebee-status index be9981e..460df0e 100755 --- a/bumblebee-status +++ b/bumblebee-status @@ -1,5 +1,6 @@ #!/usr/bin/env python +import os import sys import json import select @@ -38,13 +39,22 @@ def handle_input(output): poll.unregister(sys.stdin.fileno()) def main(): - logging.basicConfig( - level=logging.DEBUG, - format="[%(asctime)s] %(module)-16s %(levelname)-8s %(message)s", - stream=sys.stderr - ) - config = core.config.Config(sys.argv[1:]) + + level = logging.DEBUG if config.debug() else logging.ERROR + if config.logfile(): + logging.basicConfig( + level=level, + format="[%(asctime)s] %(module)-16s %(levelname)-8s %(message)s", + filename=os.path.abspath(os.path.expanduser(config.logfile())) + ) + else: + logging.basicConfig( + level=level, + format="[%(asctime)s] %(module)-16s %(levelname)-8s %(message)s", + stream=sys.stderr + ) + theme = core.theme.Theme(config.theme(), config.iconset()) output = core.output.i3(theme, config) modules = [] @@ -53,6 +63,9 @@ def main(): input_thread.daemon = True input_thread.start() + if config.debug(): + modules.append(core.module.load('debug', config, theme)) + for module in config.modules(): modules.append(core.module.load(module, config, theme)) output.modules(modules) diff --git a/core/config.py b/core/config.py index 74bb994..a9a684c 100644 --- a/core/config.py +++ b/core/config.py @@ -26,6 +26,7 @@ class Config(util.store.Store): help='Specify a list of modules to hide when not in warning/error state') parser.add_argument('-d', '--debug', action='store_true', help='Add debug fields to i3 output') + parser.add_argument('-f', '--logfile', help='destination for the debug log file, if -d|--debug is specified; defaults to stderr') self.__args = parser.parse_args(args) parameters = [ item for sub in self.__args.parameters for item in sub ] @@ -45,6 +46,9 @@ class Config(util.store.Store): def debug(self): return self.__args.debug + def logfile(self): + return self.__args.logfile + def theme(self): return self.__args.theme diff --git a/modules/core/debug.py b/modules/core/debug.py new file mode 100644 index 0000000..9df26bb --- /dev/null +++ b/modules/core/debug.py @@ -0,0 +1,22 @@ +# pylint: disable=C0111,R0903 + +"""Shows that debug is enabled""" + +import platform + +import core.module +import core.widget +import core.decorators + +class Module(core.module.Module): + @core.decorators.every(minutes=60) + def __init__(self, config, theme): + super().__init__(config, theme, core.widget.Widget(self.full_text)) + + def full_text(self, widgets): + return 'debug' + + def state(self, widget): + return 'warning' + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4