diff --git a/api/ovdashboard_api/__init__.py b/api/ovdashboard_api/__init__.py index 2ad3621..aee62c4 100644 --- a/api/ovdashboard_api/__init__.py +++ b/api/ovdashboard_api/__init__.py @@ -7,6 +7,38 @@ This file: Sets up logging. import logging.config -from .config import LogConfig +from pydantic import BaseModel + + +class LogConfig(BaseModel): + """ + Logging configuration to be set for the server. + https://stackoverflow.com/a/67937084 + """ + + LOG_FORMAT: str = "%(levelprefix)s [%(asctime)s] %(name)s: %(message)s" + LOG_LEVEL: str = "DEBUG" + + # Logging config + version = 1 + disable_existing_loggers = False + formatters = { + "default": { + "()": "uvicorn.logging.DefaultFormatter", + "fmt": LOG_FORMAT, + "datefmt": "%Y-%m-%d %H:%M:%S", + }, + } + handlers = { + "default": { + "formatter": "default", + "class": "logging.StreamHandler", + "stream": "ext://sys.stderr", + }, + } + loggers = { + "ovdashboard_api": {"handlers": ["default"], "level": LOG_LEVEL}, + } + logging.config.dictConfig(LogConfig().dict()) diff --git a/api/ovdashboard_api/config.py b/api/ovdashboard_api/config.py index c124076..c072eaf 100644 --- a/api/ovdashboard_api/config.py +++ b/api/ovdashboard_api/config.py @@ -13,35 +13,13 @@ from webdav3.exceptions import RemoteResourceNotFound from .dav_file import DavFile -class LogConfig(BaseModel): +class TickerConfig(BaseModel): """ - Logging configuration to be set for the server. - https://stackoverflow.com/a/67937084 + Sections "[ticker.*]" in "config.txt". """ - LOG_FORMAT: str = "%(levelprefix)s [%(asctime)s] %(name)s: %(message)s" - LOG_LEVEL: str = "DEBUG" - - # Logging config - version = 1 - disable_existing_loggers = False - formatters = { - "default": { - "()": "uvicorn.logging.DefaultFormatter", - "fmt": LOG_FORMAT, - "datefmt": "%Y-%m-%d %H:%M:%S", - }, - } - handlers = { - "default": { - "formatter": "default", - "class": "logging.StreamHandler", - "stream": "ext://sys.stderr", - }, - } - loggers = { - "ovdashboard_api": {"handlers": ["default"], "level": LOG_LEVEL}, - } + separator: str = " +++ " + comment_marker: str = "#" class ImageConfig(BaseModel): @@ -61,8 +39,7 @@ class Config(BaseModel): Main representation of "config.txt". """ - ticker_separator: str = " +++ " - + ticker: TickerConfig = TickerConfig() image: ImageConfig = ImageConfig() @classmethod diff --git a/api/ovdashboard_api/routers/text.py b/api/ovdashboard_api/routers/text.py index 9cddbb8..a32f5c3 100644 --- a/api/ovdashboard_api/routers/text.py +++ b/api/ovdashboard_api/routers/text.py @@ -46,10 +46,12 @@ async def get_ticker_lines() -> Iterator[str]: async def get_ticker_content_lines( ticker_lines: Iterator[str] = Depends(get_ticker_lines), ) -> Iterator[str]: + cfg = await Config.get() + return ( line for line in ticker_lines - if not line.startswith("#") + if not line.startswith(cfg.ticker.comment_marker) ) @@ -58,7 +60,7 @@ async def get_ticker_content( ) -> str: cfg = await Config.get() ticker_content_lines = ["", *ticker_content_lines, ""] - ticker_content = cfg.ticker_separator.join(ticker_content_lines) + ticker_content = cfg.ticker.separator.join(ticker_content_lines) return ticker_content.strip()