[core/config] enable logging into a log file
Re-enable the -f | --logfile parameter, but still default to logging to stderr. Also, add a "debug" module that is automatically displayed if a bar is run in debug mode (thanks to @bbernhard for the excellent suggestion) fixes #614
This commit is contained in:
parent
650942a3e3
commit
595778f7c3
3 changed files with 45 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
import select
|
import select
|
||||||
|
@ -38,13 +39,22 @@ def handle_input(output):
|
||||||
poll.unregister(sys.stdin.fileno())
|
poll.unregister(sys.stdin.fileno())
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
config = core.config.Config(sys.argv[1:])
|
||||||
|
|
||||||
|
level = logging.DEBUG if config.debug() else logging.ERROR
|
||||||
|
if config.logfile():
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.DEBUG,
|
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",
|
format="[%(asctime)s] %(module)-16s %(levelname)-8s %(message)s",
|
||||||
stream=sys.stderr
|
stream=sys.stderr
|
||||||
)
|
)
|
||||||
|
|
||||||
config = core.config.Config(sys.argv[1:])
|
|
||||||
theme = core.theme.Theme(config.theme(), config.iconset())
|
theme = core.theme.Theme(config.theme(), config.iconset())
|
||||||
output = core.output.i3(theme, config)
|
output = core.output.i3(theme, config)
|
||||||
modules = []
|
modules = []
|
||||||
|
@ -53,6 +63,9 @@ def main():
|
||||||
input_thread.daemon = True
|
input_thread.daemon = True
|
||||||
input_thread.start()
|
input_thread.start()
|
||||||
|
|
||||||
|
if config.debug():
|
||||||
|
modules.append(core.module.load('debug', config, theme))
|
||||||
|
|
||||||
for module in config.modules():
|
for module in config.modules():
|
||||||
modules.append(core.module.load(module, config, theme))
|
modules.append(core.module.load(module, config, theme))
|
||||||
output.modules(modules)
|
output.modules(modules)
|
||||||
|
|
|
@ -26,6 +26,7 @@ class Config(util.store.Store):
|
||||||
help='Specify a list of modules to hide when not in warning/error state')
|
help='Specify a list of modules to hide when not in warning/error state')
|
||||||
parser.add_argument('-d', '--debug', action='store_true',
|
parser.add_argument('-d', '--debug', action='store_true',
|
||||||
help='Add debug fields to i3 output')
|
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)
|
self.__args = parser.parse_args(args)
|
||||||
|
|
||||||
parameters = [ item for sub in self.__args.parameters for item in sub ]
|
parameters = [ item for sub in self.__args.parameters for item in sub ]
|
||||||
|
@ -45,6 +46,9 @@ class Config(util.store.Store):
|
||||||
def debug(self):
|
def debug(self):
|
||||||
return self.__args.debug
|
return self.__args.debug
|
||||||
|
|
||||||
|
def logfile(self):
|
||||||
|
return self.__args.logfile
|
||||||
|
|
||||||
def theme(self):
|
def theme(self):
|
||||||
return self.__args.theme
|
return self.__args.theme
|
||||||
|
|
||||||
|
|
22
modules/core/debug.py
Normal file
22
modules/core/debug.py
Normal file
|
@ -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
|
Loading…
Reference in a new issue