mirror of
https://github.com/BOSWatch/BW3-Core.git
synced 2025-12-06 07:12:04 +01:00
Merge pull request #135 from KoenigMjr/feature/log-multi-clients
Some checks failed
build_docs / Build documentation (push) Has been cancelled
build_docs / deploy (push) Has been cancelled
CodeQL / CodeQL-Build (push) Has been cancelled
pytest / build (ubuntu-latest, 3.10) (push) Has been cancelled
pytest / build (ubuntu-latest, 3.11) (push) Has been cancelled
pytest / build (ubuntu-latest, 3.12) (push) Has been cancelled
pytest / build (ubuntu-latest, 3.13) (push) Has been cancelled
pytest / build (ubuntu-latest, 3.9) (push) Has been cancelled
Some checks failed
build_docs / Build documentation (push) Has been cancelled
build_docs / deploy (push) Has been cancelled
CodeQL / CodeQL-Build (push) Has been cancelled
pytest / build (ubuntu-latest, 3.10) (push) Has been cancelled
pytest / build (ubuntu-latest, 3.11) (push) Has been cancelled
pytest / build (ubuntu-latest, 3.12) (push) Has been cancelled
pytest / build (ubuntu-latest, 3.13) (push) Has been cancelled
pytest / build (ubuntu-latest, 3.9) (push) Has been cancelled
feat(logging): dynamische Logdateibenennung des Client basierend auf YAML-Datei
This commit is contained in:
commit
7ae6dfa820
36
bw_client.py
36
bw_client.py
|
|
@ -10,7 +10,7 @@ r"""!
|
|||
by Bastian Schroll
|
||||
|
||||
@file: bw_client.py
|
||||
@date: 09.12.2017
|
||||
@date: 16.07.2025
|
||||
@author: Bastian Schroll
|
||||
@description: BOSWatch client application
|
||||
"""
|
||||
|
|
@ -27,8 +27,31 @@ if not paths.makeDirIfNotExist(paths.LOG_PATH):
|
|||
print("cannot find/create log directory: %s", paths.LOG_PATH)
|
||||
exit(1)
|
||||
|
||||
import logging
|
||||
import logging.config
|
||||
logging.config.fileConfig(paths.CONFIG_PATH + "logger_client.ini")
|
||||
import logging.handlers
|
||||
import argparse
|
||||
import os
|
||||
import builtins
|
||||
|
||||
# parsing arguments first - this is needed to load the logging config file with the correct log filename
|
||||
parser = argparse.ArgumentParser(prog="bw_client.py",
|
||||
description="""BOSWatch is a Python Script to receive and
|
||||
decode german BOS information with rtl_fm and multimon-NG""",
|
||||
epilog="""More options you can find in the extern client.ini
|
||||
file in the folder /config""")
|
||||
# With -h or --help you get the Args help
|
||||
parser.add_argument("-c", "--config", help="Name to configuration File", required=True)
|
||||
parser.add_argument("-t", "--test", help="Start Client with testdata-set", action="store_true")
|
||||
args = parser.parse_args()
|
||||
|
||||
# set the log filename in the global namespace (mandatory for fileConfig)
|
||||
basename = os.path.splitext(args.config)[0]
|
||||
log_filename = f"{paths.LOG_PATH}{basename}.log"
|
||||
builtins.log_filename = log_filename
|
||||
|
||||
logging.config.fileConfig(paths.CONFIG_PATH + "logger_client.ini", disable_existing_loggers=False)
|
||||
|
||||
logging.debug("")
|
||||
logging.debug("######################## NEW LOG ############################")
|
||||
logging.debug("BOSWatch client has started ...")
|
||||
|
|
@ -56,15 +79,6 @@ from boswatch.decoder.decoder import Decoder # for test mode
|
|||
header.logoToLog()
|
||||
header.infoToLog()
|
||||
|
||||
# With -h or --help you get the Args help
|
||||
parser = argparse.ArgumentParser(prog="bw_client.py",
|
||||
description="""BOSWatch is a Python Script to receive and
|
||||
decode german BOS information with rtl_fm and multimon-NG""",
|
||||
epilog="""More options you can find in the extern client.ini
|
||||
file in the folder /config""")
|
||||
parser.add_argument("-c", "--config", help="Name to configuration File", required=True)
|
||||
parser.add_argument("-t", "--test", help="Start Client with testdata-set", action="store_true")
|
||||
args = parser.parse_args()
|
||||
|
||||
bwConfig = ConfigYAML()
|
||||
if not bwConfig.loadConfigFile(paths.CONFIG_PATH + args.config):
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ keys=root
|
|||
[logger_root]
|
||||
handlers=screen,file
|
||||
level=NOTSET
|
||||
# NOTSET means: accept all levels (the handlers will filter by their own level)
|
||||
|
||||
[formatters]
|
||||
keys=simple,complex
|
||||
|
|
@ -30,11 +31,14 @@ keys=file,screen
|
|||
|
||||
[handler_file]
|
||||
class=handlers.TimedRotatingFileHandler
|
||||
interval=midnight
|
||||
backupCount=7
|
||||
formatter=complex
|
||||
level=ERROR
|
||||
args=('log/client.log',)
|
||||
args=(log_filename, 'midnight', 1, 7, 'utf-8')
|
||||
# explaining args:
|
||||
# - 'midnight' → rotate daily at midnight, Options: 'S', 'M', 'H', 'D', 'midnight' or 'W0'-'W6' (0=Monday, 6=Sunday)
|
||||
# - 1 → rotate every 1 "x" (see line above), Options: 1, 2, ..., 31
|
||||
# - 7 → keep last 7 logs, Options: 1, 2, ..., 31
|
||||
# - 'utf-8' → encoding of the log file, don't change
|
||||
|
||||
[handler_screen]
|
||||
class=StreamHandler
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ keys=root
|
|||
[logger_root]
|
||||
handlers=screen,file
|
||||
level=NOTSET
|
||||
# NOTSET means: accept all levels (the handlers will filter by their own level)
|
||||
|
||||
[formatters]
|
||||
keys=simple,complex
|
||||
|
|
@ -30,11 +31,14 @@ keys=file,screen
|
|||
|
||||
[handler_file]
|
||||
class=handlers.TimedRotatingFileHandler
|
||||
interval=midnight
|
||||
backupCount=7
|
||||
formatter=complex
|
||||
level=ERROR
|
||||
args=('log/server.log',)
|
||||
args=('log/server.log', 'midnight', 1, 7, 'utf-8')
|
||||
# explaining args:
|
||||
# - 'midnight' → rotate daily at midnight, Options: 'S', 'M', 'H', 'D', 'midnight' or 'W0'-'W6' (0=Monday, 6=Sunday)
|
||||
# - 1 → rotate every 1 "x" (see line above), Options: 1, 2, ..., 31
|
||||
# - 7 → keep last 7 logs, Options: 1, 2, ..., 31
|
||||
# - 'utf-8' → encoding of the log file, don't change
|
||||
|
||||
[handler_screen]
|
||||
class=StreamHandler
|
||||
|
|
|
|||
Loading…
Reference in a new issue