Log to journald
This commit is contained in:
parent
a009564b74
commit
4c7a4cbd36
@ -6,7 +6,9 @@ version = 0.0.1
|
||||
package_dir =
|
||||
=src
|
||||
packages = find_namespace:
|
||||
# install_requires =
|
||||
install_requires =
|
||||
systemd-python==234
|
||||
typer==0.3.2
|
||||
|
||||
[options.packages.find]
|
||||
where = src
|
||||
|
@ -9,6 +9,8 @@ from citadel.mqtt import Client
|
||||
from .app import Yamaha
|
||||
from .senario import load_from_file, SENARIOS
|
||||
|
||||
import systemd.journal
|
||||
|
||||
def main(\
|
||||
mqtt_user: str = typer.Option(... , envvar="YAMAHA_MQTT_USER"),\
|
||||
mqtt_pwd: str = typer.Option(... , envvar="YAMAHA_MQTT_PWD"),\
|
||||
@ -17,9 +19,27 @@ def main(\
|
||||
yamaha_host: str = typer.Option(... , envvar="YAMAHA_HOST"),\
|
||||
senarios_file: Optional[Path] = typer.Option(None, exists=True,
|
||||
file_okay=True, dir_okay=False, readable=True, resolve_path=True,
|
||||
envvar="YAMAHA_SENARIOS")\
|
||||
envvar="YAMAHA_SENARIOS"),\
|
||||
is_systemd: bool = typer.Option(False, help="Is running as systemd unit", envvar="LAUNCHED_BY_SYSTEMD")\
|
||||
):
|
||||
|
||||
if is_systemd:
|
||||
logger = logging.getLogger('')
|
||||
logger.setLevel(logging.DEBUG)
|
||||
logger.addHandler(systemd.journal.JournalHandler())
|
||||
else:
|
||||
logger = logging.getLogger('')
|
||||
logger.setLevel(logging.DEBUG)
|
||||
# create console handler and set level to debug
|
||||
ch = logging.StreamHandler()
|
||||
ch.setLevel(logging.DEBUG)
|
||||
# create formatter
|
||||
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
# add formatter to ch
|
||||
ch.setFormatter(formatter)
|
||||
# add ch to logger
|
||||
logger.addHandler(ch)
|
||||
|
||||
if senarios_file:
|
||||
load_from_file(senarios_file)
|
||||
|
||||
@ -29,25 +49,9 @@ def main(\
|
||||
|
||||
client.loop_forever()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# create logger
|
||||
logger = logging.getLogger('')
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
# create console handler and set level to debug
|
||||
ch = logging.StreamHandler()
|
||||
ch.setLevel(logging.DEBUG)
|
||||
|
||||
# create formatter
|
||||
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
|
||||
# add formatter to ch
|
||||
ch.setFormatter(formatter)
|
||||
|
||||
# add ch to logger
|
||||
logger.addHandler(ch)
|
||||
|
||||
#deactive urllib3 logger too verbose
|
||||
#deactivate urllib3 logger too verbose
|
||||
logger = logging.getLogger('urllib3')
|
||||
logger.setLevel(logging.ERROR)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user