Add invocation ID and logger name to JSON log
Update typehint Update docstring
This commit is contained in:
parent
6b67078129
commit
77781d5c4d
1 changed files with 8 additions and 3 deletions
|
|
@ -56,6 +56,7 @@ def configure_logging(log_folder: str, debug: bool = False) -> None:
|
|||
ofm_format_str = "[%(asctime)s] [%(levelname)s] %(message)s"
|
||||
OFM_HANDLER.setFormatter(OFMLogFileFormatter(ofm_format_str))
|
||||
OFM_HANDLER.addFilter(UvicornAccessFilter())
|
||||
OFM_HANDLER.addFilter(inject_invocation_id)
|
||||
OFM_HANDLER.level = root_logger.level
|
||||
root_logger.addHandler(OFM_HANDLER)
|
||||
|
||||
|
|
@ -156,7 +157,7 @@ class OFMHandler(logging.Handler):
|
|||
how many can be returned over HTTP.
|
||||
"""
|
||||
super().__init__(level=level)
|
||||
self._log: list[str] = []
|
||||
self._log: list[dict] = []
|
||||
self._max_logs = max_logs
|
||||
# start at -1 so first record is 0
|
||||
self._running_counter = -1
|
||||
|
|
@ -170,8 +171,9 @@ class OFMHandler(logging.Handler):
|
|||
"level": record.levelname,
|
||||
"summary": msg.split("\n")[0],
|
||||
"message": msg,
|
||||
"invocation_id": getattr(record, "invocation_id", None),
|
||||
"logger": record.name,
|
||||
"sequence": self._running_counter,
|
||||
"expanded": False,
|
||||
}
|
||||
|
||||
def append_record(self, record: logging.LogRecord) -> None:
|
||||
|
|
@ -199,7 +201,10 @@ class OFMHandler(logging.Handler):
|
|||
|
||||
@property
|
||||
def log_history(self) -> list[dict]:
|
||||
"""Return the log history up to the maximum number of logs."""
|
||||
"""Return the log history up to the maximum number of logs.
|
||||
|
||||
Order is reversed so most recent logs are at the top.
|
||||
"""
|
||||
return list(reversed(self._log))
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue