Improve typehinting for logging
This commit is contained in:
parent
3529c96ec6
commit
95969c5daa
1 changed files with 4 additions and 4 deletions
|
|
@ -103,7 +103,7 @@ def retrieve_log_from_file() -> PlainTextResponse:
|
||||||
class OFMLogFileFormatter(logging.Formatter):
|
class OFMLogFileFormatter(logging.Formatter):
|
||||||
"""The formatter used for the OpenFlexure Microscope Server log file."""
|
"""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.
|
"""Adjust the logging formatting for uvicorn logs.
|
||||||
|
|
||||||
Any ``uvicorn.error`` logs that are at a lower
|
Any ``uvicorn.error`` logs that are at a lower
|
||||||
|
|
@ -134,7 +134,7 @@ class OFMHandler(logging.Handler):
|
||||||
self._log = []
|
self._log = []
|
||||||
self._max_logs = max_logs
|
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.
|
"""Format message and append it to a list of records.
|
||||||
|
|
||||||
The built in formatter is used to format the record.
|
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:
|
while len(self._log) > self._max_logs:
|
||||||
self._log.pop(0)
|
self._log.pop(0)
|
||||||
|
|
||||||
def emit(self, record):
|
def emit(self, record: logging.LogRecord):
|
||||||
"""Emit will save the logged record to the log."""
|
"""Emit will save the logged record to the log."""
|
||||||
try:
|
try:
|
||||||
if record.levelno >= self.level:
|
if record.levelno >= self.level:
|
||||||
|
|
@ -166,7 +166,7 @@ class OFMHandler(logging.Handler):
|
||||||
class UvicornAccessFilter(logging.Filter):
|
class UvicornAccessFilter(logging.Filter):
|
||||||
"""A logging filter to filter out "uvicorn.access" messages."""
|
"""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 False if record is from "uvicorn.access"."""
|
||||||
return not record.name.startswith("uvicorn.access")
|
return not record.name.startswith("uvicorn.access")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue