Merge pull request #192 from gyptazy/tecdebt/185-improve-logging-code

tecdebt: Improve logging handler creation
This commit is contained in:
Florian
2025-04-14 06:55:51 +02:00
committed by GitHub
3 changed files with 14 additions and 18 deletions

View File

@@ -1,2 +1,2 @@
fix:
- add handler to log messages with severity less than info to the screen when there is no systemd integration, for instance, inside a docker container. [#185]
- add handler to log messages with severity less than info to the screen when there is no systemd integration, for instance, inside a docker container (by @glitchvern) [#185]

View File

@@ -1,2 +1,2 @@
fixed:
- allow the use of minutes instead of hours and only accept hours or minutes in the format [#187]
- allow the use of minutes instead of hours and only accept hours or minutes in the format (by @glitchvern) [#187]

View File

@@ -83,26 +83,22 @@ class SystemdLogger:
self.logger = logging.getLogger(name)
self.logger.setLevel(level)
# Create a JournalHandler for systemd integration if this
# is supported on the underlying OS.
# Create a logging handler depending on the
# capabilities of the underlying OS where systemd
# logging is preferred.
if SYSTEMD_PRESENT:
# Add a JournalHandler for systemd integration
journal_handler = JournalHandler()
journal_handler.setLevel(level)
# Set a formatter to include the logger's name and log message
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
journal_handler.setFormatter(formatter)
# Add handler to logger
self.logger.addHandler(journal_handler)
handler = JournalHandler()
else:
# Add a handler for no systemd integration
# Add a stdout handler as a fallback
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(level)
# Set a formatter to include the logger's name and log message
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
# Add handler to logger
self.logger.addHandler(handler)
handler.setLevel(level)
# Set a formatter to include the logger's name and log message
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
# Add handler to logger
self.logger.addHandler(handler)
def set_log_level(self, level: str) -> None:
"""