tuhi: log the tuhi server session data to a file
Storage is $XDG_DATA_HOME/tuhi/session-logs/tuhi-$DATE.log Because it's really useful to have the logs of an old session around when something goes wrong. Even for simple things like "what uuid was I using again?" Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
9ef4002b39
commit
f742779c1a
15
tuhi/base.py
15
tuhi/base.py
|
@ -423,6 +423,19 @@ class Tuhi(GObject.Object):
|
|||
self.bluez.stop_discovery()
|
||||
|
||||
|
||||
def setup_logging(config_dir):
|
||||
session_log_file = Path(config_dir, 'session-logs', f'tuhi-{time.strftime("%y-%m-%d-%H:%M:%S")}.log')
|
||||
session_log_file.parent.mkdir(parents=True, exist_ok=True)
|
||||
fh = logging.FileHandler(session_log_file)
|
||||
fh.setLevel(logging.DEBUG)
|
||||
|
||||
ch = logging.StreamHandler()
|
||||
ch.setLevel(logging.ERROR)
|
||||
logger.addHandler(ch)
|
||||
logger.addHandler(fh)
|
||||
logger.info(f'Session log: {session_log_file}')
|
||||
|
||||
|
||||
def main(args=sys.argv):
|
||||
if sys.version_info < (3, 6):
|
||||
sys.exit('Python 3.6 or later required')
|
||||
|
@ -439,6 +452,8 @@ def main(args=sys.argv):
|
|||
default=DEFAULT_CONFIG_PATH)
|
||||
|
||||
ns = parser.parse_args(args[1:])
|
||||
setup_logging(ns.config_dir)
|
||||
|
||||
if ns.verbose:
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
|
|
Loading…
Reference in New Issue