Format log history for fallback server
This commit is contained in:
parent
66e3e23812
commit
bfa5183c30
2 changed files with 13 additions and 3 deletions
|
|
@ -207,6 +207,18 @@ class OFMHandler(logging.Handler):
|
||||||
"""
|
"""
|
||||||
return list(reversed(self._log))
|
return list(reversed(self._log))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def get_formatted_log_history(self) -> str:
|
||||||
|
"""Return the log history as a formatted string.
|
||||||
|
|
||||||
|
This is to be used for the fallback server, the formatting does not contain invocation
|
||||||
|
IDs as no actions should have started.
|
||||||
|
"""
|
||||||
|
output = ""
|
||||||
|
for entry in self._log:
|
||||||
|
output += f"[{entry['timestamp']} [{entry['level']}] <{entry['logger']}> {entry['message']}\n"
|
||||||
|
return output
|
||||||
|
|
||||||
|
|
||||||
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."""
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import json
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from argparse import Namespace
|
from argparse import Namespace
|
||||||
|
|
@ -151,8 +150,7 @@ def serve_from_cli(argv: Optional[list[str]] = None) -> None:
|
||||||
print(f"Error: {e}") # noqa: T201
|
print(f"Error: {e}") # noqa: T201
|
||||||
print("Starting fallback server.") # noqa: T201
|
print("Starting fallback server.") # noqa: T201
|
||||||
try:
|
try:
|
||||||
# The log is a list of dicts, fallback server expects a string
|
log_history = OFM_HANDLER.get_formatted_log_history
|
||||||
log_history = json.dumps(OFM_HANDLER.log_history, indent=2)
|
|
||||||
except BaseException:
|
except BaseException:
|
||||||
# If log history fails for any reason carry on.
|
# If log history fails for any reason carry on.
|
||||||
log_history = None
|
log_history = None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue