Logging implementiert
This commit is contained in:
parent
dafcfaca6b
commit
d7136e38bf
35
obp60v.py
35
obp60v.py
|
@ -84,6 +84,7 @@ Version Datum Änderung(en) von
|
|||
import os
|
||||
import sys
|
||||
import configparser
|
||||
import logging, logging.handlers
|
||||
from setproctitle import setproctitle, setthreadtitle
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
|
@ -632,10 +633,37 @@ def init_profile(config, cfg, boatdata):
|
|||
c = cls(i, cfg, boatdata, *[v for v in p['values'].values()])
|
||||
clist[i] = c
|
||||
return clist
|
||||
|
||||
def set_loglevel(nr):
|
||||
"""
|
||||
Umsetzen der Nummer auf einen für "logging" passenden Wert
|
||||
Die Nummer kann ein Wert zwischen 0 - kein Logging und 5 - Debug sein
|
||||
"""
|
||||
level = (None, logging.CRITICAL, logging.ERROR, logging.WARNING,
|
||||
logging.INFO, logging.DEBUG)
|
||||
if nr > 5:
|
||||
nr = 5
|
||||
elif nr < 0:
|
||||
nr = 0
|
||||
return level[nr]
|
||||
|
||||
def init_logging(logdir):
|
||||
global log
|
||||
os.makedirs(logdir, exist_ok=True)
|
||||
log = logging.getLogger(os.path.basename(sys.argv[0]))
|
||||
hdlr = logging.handlers.RotatingFileHandler(os.path.join(logdir, 'obp60v.log'), maxBytes=5242880, backupCount=5)
|
||||
formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
|
||||
hdlr.setFormatter(formatter)
|
||||
log.addHandler(hdlr)
|
||||
log.setLevel(logging.INFO)
|
||||
console = logging.StreamHandler()
|
||||
console.setFormatter(logging.Formatter('%(levelname)s:%(message)s'))
|
||||
console.setLevel(logging.INFO)
|
||||
log.addHandler(console)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
#setproctitle("obp60v")
|
||||
setproctitle("obp60v")
|
||||
|
||||
shutdown = False
|
||||
|
||||
|
@ -700,6 +728,11 @@ if __name__ == "__main__":
|
|||
if cfg['simulation']:
|
||||
boatdata.enableSimulation()
|
||||
|
||||
# Protokollierung
|
||||
init_logging(os.path.expanduser("~/.local/share/obp60v"))
|
||||
log.info("Logging initialized")
|
||||
|
||||
# Gerät initialisieren u.a. mit den genutzten Seiten
|
||||
profile = init_profile(config, cfg, boatdata)
|
||||
|
||||
# Schnittstellen aktivieren
|
||||
|
|
Loading…
Reference in New Issue