Improve typehinting for logging

This commit is contained in:
Julian Stirling 2025-08-21 15:49:00 +01:00
parent 3529c96ec6
commit 95969c5daa

View file

@ -103,7 +103,7 @@ def retrieve_log_from_file() -> PlainTextResponse:
class OFMLogFileFormatter(logging.Formatter):
"""The formatter used for the OpenFlexure Microscope Server log file."""
def format(self, record):
def format(self, record: logging.LogRecord):
"""Adjust the logging formatting for uvicorn logs.
Any ``uvicorn.error`` logs that are at a lower
@ -134,7 +134,7 @@ class OFMHandler(logging.Handler):
self._log = []
self._max_logs = max_logs
def append_record(self, record):
def append_record(self, record: logging.LogRecord):
"""Format message and append it to a list of records.
The built in formatter is used to format the record.
@ -145,7 +145,7 @@ class OFMHandler(logging.Handler):
while len(self._log) > self._max_logs:
self._log.pop(0)
def emit(self, record):
def emit(self, record: logging.LogRecord):
"""Emit will save the logged record to the log."""
try:
if record.levelno >= self.level:
@ -166,7 +166,7 @@ class OFMHandler(logging.Handler):
class UvicornAccessFilter(logging.Filter):
"""A logging filter to filter out "uvicorn.access" messages."""
def filter(self, record):
def filter(self, record: logging.LogRecord):
"""Return False if record is from "uvicorn.access"."""
return not record.name.startswith("uvicorn.access")