From 8c02763e558cf1783e32d39bc69a49d3b20e5a1f Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Sun, 27 Jul 2025 13:39:59 +0200 Subject: [PATCH] Adaption to default logging method --- config_example/config.j2 | 28 ++++++++++++++-------------- powerplug.py | 9 +-------- report | 2 +- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/config_example/config.j2 b/config_example/config.j2 index aa9628b..5e0add9 100644 --- a/config_example/config.j2 +++ b/config_example/config.j2 @@ -1,22 +1,22 @@ #!/usr/bin/env python # -*- coding: UTF-8 -*- import os -import report +import logging + +DEBUG = False +# +# Logging +# +APP_NAME = "powerplug" +LOG_HOSTNAME = "loggy" # When DEBUG is True +LOG_LEVEL = logging.INFO # STDOUT logging + + +# +# Application +# MQTT_USER = "{{ smart_sat_powerplug_username }}" MQTT_PASS = "{{ smart_sat_powerplug_password }}" MQTT_SERVER = "{{ smart_sat_powerplug_hostname }}" MQTT_TOPIC = "{{ smart_sat_powerplug_topic }}" - -# -# Logging -# -__BASEPATH__ = os.path.abspath(os.path.dirname(__file__)) -APP_NAME = "powerplug" -LOGTARGET = 'stdout' # possible choices are: 'logfile' or 'stdout' -LOGLVL = 'INFO' - -LOGHOST = 'cutelog' -LOGPORT = 19996 - -formatter = report.SHORT_FMT diff --git a/powerplug.py b/powerplug.py index 351a1b8..20a9da5 100644 --- a/powerplug.py +++ b/powerplug.py @@ -1,16 +1,11 @@ import config -import logging import mqtt import report import socket import subprocess import time -try: - from config import APP_NAME as ROOT_LOGGER_NAME -except ImportError: - ROOT_LOGGER_NAME = 'root' -logger = logging.getLogger(ROOT_LOGGER_NAME).getChild('main') +logger = report.default_logging_config() class sispmctl(object): @@ -103,8 +98,6 @@ class mqtt_powerplug(mqtt.mqtt_client): if __name__ == '__main__': - report.appLoggingConfigure(config.__BASEPATH__, config.LOGTARGET, ((config.APP_NAME, config.LOGLVL), ), fmt=config.formatter, host=config.LOGHOST, port=config.LOGPORT) - # mp = mqtt_powerplug() while True: diff --git a/report b/report index 21bac82..60be783 160000 --- a/report +++ b/report @@ -1 +1 @@ -Subproject commit 21bac82e0c459ebf6d34783c9249526a657a6bbd +Subproject commit 60be78310ee6b6a5a091f27f9e5e514927d7520f