From beb350978e1b77d5163ea44ffe973abe1c6ecb10 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Tue, 14 Nov 2023 18:33:23 +0100 Subject: [PATCH] add debug-log-level to config.yaml to enable different logging level also in cbpi service --- cbpi/__init__.py | 2 +- cbpi/cli.py | 21 ++++++++++++++++----- cbpi/config/config.yaml | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 8b1edcf..21977a3 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.2.0.a8" +__version__ = "4.2.0.a9" __codename__ = "Indian Summer" diff --git a/cbpi/cli.py b/cbpi/cli.py index dbfdb60..1221547 100644 --- a/cbpi/cli.py +++ b/cbpi/cli.py @@ -1,6 +1,7 @@ import logging from pathlib import Path import requests +from cbpi import __version__, __codename__ from cbpi.configFolder import ConfigFolder from cbpi.utils.utils import load_config from zipfile import ZipFile @@ -258,16 +259,26 @@ class CraftBeerPiCli(): @click.pass_context @click.option('--config-folder-path', '-c', default="./config", type=click.Path(), help="Specify where the config folder is located. Defaults to './config'.") @click.option('--logs-folder-path', '-l', default="", type=click.Path(), help="Specify where the log folder is located. Defaults to '../logs' relative from the config folder.") -@click.option('--debug-log-level', '-d', default="30", type=int, help="Specify the log level you want to write to all logs. 0=ALL, 10=DEBUG, 20=INFO 30(default)=WARNING, 40=ERROR, 50=CRITICAL") +@click.option('--debug-log-level', '-d', default="99", type=int, help="Specify the log level you want to write to all logs. 0=ALL, 10=DEBUG, 20=INFO 30(default)=WARNING, 40=ERROR, 50=CRITICAL. Can be also set in config.yaml (debug-log-level: INT)") def main(context, config_folder_path, logs_folder_path, debug_log_level): - print("---------------------") - print("Welcome to CBPi") - print("---------------------") + print("--------------------------") + print("Welcome to CBPi "+__version__) + print("--------------------------") if logs_folder_path == "": logs_folder_path = os.path.join(Path(config_folder_path).absolute().parent, 'logs') formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(name)s - %(message)s') + static_config = load_config(ConfigFolder(config_folder_path, logs_folder_path).get_file_path("config.yaml")) + try: + if debug_log_level == 99: + debug_log_level=static_config['debug-log-level'] + except: + debug_log_level=30 + logging.basicConfig(format=formatter, stream=logging.StreamHandler()) logger = logging.getLogger() + print("*******************************") + print("Set Debug-log-level to {}".format(debug_log_level)) + print("*******************************") logger.setLevel(debug_log_level) try: if not os.path.isdir(logs_folder_path): @@ -292,7 +303,7 @@ def setup(context): @click.option('--list', is_flag=True, help="List all 1Wire Devices") @click.option('--setup', is_flag=True, help="Setup 1Wire on Raspberry Pi") def onewire(context, list, setup): - '''Setup 1wire on Raspberry Pi''' + '''(--setup | --list) Setup 1wire on Raspberry Pi or list sensors''' if setup is True: context.obj.setup_one_wire() if list is True: diff --git a/cbpi/config/config.yaml b/cbpi/config/config.yaml index 2f05625..b15c777 100644 --- a/cbpi/config/config.yaml +++ b/cbpi/config/config.yaml @@ -5,7 +5,7 @@ version: 4.0.8 index_url: /cbpi_ui/static/index.html port: 8000 - +debug-log-level: 30 mqtt: false mqtt_host: localhost mqtt_port: 1883