logging setup

This commit is contained in:
Jörn-Michael Miehe 2022-09-04 23:25:40 +00:00
parent 791a196e15
commit 161e0e9628
4 changed files with 38 additions and 4 deletions

View file

@ -0,0 +1,5 @@
import logging.config
from .config import LogConfig
logging.config.dictConfig(LogConfig().dict())

View file

@ -11,6 +11,37 @@ from .dav_common import webdav_resource
from .dav_file import DavFile
class LogConfig(BaseModel):
"""
https://stackoverflow.com/a/67937084
Logging configuration to be set for the server
"""
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},
}
class ImageConfig(BaseModel):
mode: str = "RGB"
save_params: dict[str, Any] = {

View file

@ -78,8 +78,7 @@ async def _get_calendar_events(
@run_in_executor
def _inner() -> Iterator[VEvent]:
_logger.info(f"updating {calendar_name}")
print(f"updating {calendar_name}")
_logger.info(f"updating {calendar_name!r} ...")
calendar = caldav_principal().calendar(calendar_name)

View file

@ -18,8 +18,7 @@ async def _get_buffer(
@run_in_executor
def _inner(resource: Resource) -> BytesIO:
_logger.info(f"updating {resource}")
print(f"updating {resource}")
_logger.info(f"updating {resource.urn.filename()!r} ...")
buffer = BytesIO()
resource.write_to(buffer)
return buffer