Skip to content

Commit 030485b

Browse files
committed
Fehlerbehebung: Logging-Setup für Multi-Client-Betrieb korrigiert
- Logdateipfad wird vor dem Aufruf von fileConfig() über builtins.log_filename gesetzt - Entfernt manuelles Patchen des Loghandlers (BaseFilename, Stream etc.) nach dem Laden - Logging-Konfiguration (logger_client.ini) wird nur noch einmal geladen - logger_*.ini: Korrektur: interval=midnight ist nicht (mehr) offiziell unterstützt, Änderung auf korrekte Schreibweise (when=midnight, interval=1) - Ändern der Kommentare auf Englisch (stringent zu anderen Kommentaren)
1 parent 676312e commit 030485b

3 files changed

Lines changed: 12 additions & 16 deletions

File tree

bw_client.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
import logging.config
3131
import argparse
3232
import os
33+
import builtins
3334

34-
# Argumente zuerst parsen
35+
# parsing arguments first - this is needed to load the logging config file with the correct log filename
3536
parser = argparse.ArgumentParser(prog="bw_client.py",
3637
description="""BOSWatch is a Python Script to receive and
3738
decode german BOS information with rtl_fm and multimon-NG""",
@@ -42,20 +43,13 @@
4243
parser.add_argument("-t", "--test", help="Start Client with testdata-set", action="store_true")
4344
args = parser.parse_args()
4445

45-
# Logging-Konfiguration laden
46-
logging.config.fileConfig(paths.CONFIG_PATH + "logger_client.ini", disable_existing_loggers=False)
47-
48-
# Dynamischer Logdateiname basierend auf YAML-Datei
49-
yaml_basename = os.path.splitext(args.config)[0]
50-
log_filename = f"{paths.LOG_PATH}{yaml_basename}.log"
46+
# set the log filename in the global namespace (mandatory for fileConfig)
47+
log_filename = f"{paths.LOG_PATH}{os.path.splitext(args.config)[0]}.log"
48+
builtins.log_filename = log_filename
5149

52-
for handler in logging.getLogger().handlers:
53-
if isinstance(handler, logging.handlers.TimedRotatingFileHandler):
54-
handler.baseFilename = os.path.abspath(log_filename)
55-
handler.stream.close()
56-
handler.stream = open(handler.baseFilename, handler.mode)
50+
logging.config.fileConfig(paths.CONFIG_PATH + "logger_client.ini", disable_existing_loggers=False)
5751

58-
# Placeholder-Logdatei löschen, falls dynamisch umgebogen
52+
# delete the placeholder log file if it exists and is not the current log file
5953
placeholder_log = os.path.abspath(os.path.join(paths.LOG_PATH, "client.log"))
6054
if os.path.abspath(log_filename) != placeholder_log and os.path.isfile(placeholder_log):
6155
try:

config/logger_client.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ keys=file,screen
3030

3131
[handler_file]
3232
class=handlers.TimedRotatingFileHandler
33-
interval=midnight
33+
when=midnight
34+
interval=1
3435
backupCount=7
3536
formatter=complex
3637
level=ERROR
37-
args=('log/client.log',)
38+
args=(log_filename,)
3839

3940
[handler_screen]
4041
class=StreamHandler

config/logger_server.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ keys=file,screen
3030

3131
[handler_file]
3232
class=handlers.TimedRotatingFileHandler
33-
interval=midnight
33+
when=midnight
34+
interval=1
3435
backupCount=7
3536
formatter=complex
3637
level=ERROR

0 commit comments

Comments
 (0)