From 5996bb1fc0fb788e92202b25c57f7715e00cdb33 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Wed, 19 Nov 2025 13:45:26 +0900 Subject: [PATCH] Add Log ConsoleFormatSettings.from_string static method to get settings by name with default option To help set from config or command line with fallback --- src/corelibs/logging_handling/log.py | 16 ++++++++++++++++ test-run/logging_handling/log.py | 1 + 2 files changed, 17 insertions(+) diff --git a/src/corelibs/logging_handling/log.py b/src/corelibs/logging_handling/log.py index d4c7c7e..f774d03 100644 --- a/src/corelibs/logging_handling/log.py +++ b/src/corelibs/logging_handling/log.py @@ -52,6 +52,22 @@ class ConsoleFormatSettings: # only message BARE = ConsoleFormat(0) + @staticmethod + def from_string(setting_str: str, default: ConsoleFormat | None = None) -> ConsoleFormat | None: + """ + Get a console format setting, if does not exist set to None + + Arguments: + setting_str {str} -- what to search for + default {ConsoleFormat | None} -- if not found return this (default: {None}) + + Returns: + ConsoleFormat | None -- found ConsoleFormat or None + """ + if hasattr(ConsoleFormatSettings, setting_str): + return getattr(ConsoleFormatSettings, setting_str) + return default + # MARK: Log settings TypedDict class LogSettings(TypedDict): diff --git a/test-run/logging_handling/log.py b/test-run/logging_handling/log.py index df65f62..769bd74 100644 --- a/test-run/logging_handling/log.py +++ b/test-run/logging_handling/log.py @@ -37,6 +37,7 @@ def main(): log.info("ConsoleFormatType FILE is: %s", ConsoleFormat.FILE) log.info("ConsoleFormatSettings ALL is: %s", ConsoleFormatSettings.ALL) + log.info("ConsoleFormatSettings lookup is: %s", ConsoleFormatSettings.from_string('ALL')) log.logger.debug('[NORMAL] Debug test: %s', log.logger.name) log.lg.debug('[NORMAL] Debug test: %s', log.logger.name)