From c7db69a30c475db5b5de089c700dd6a581e1de96 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Fri, 26 May 2023 09:05:44 +0200 Subject: [PATCH] add timestamps to HTML debug output --- nominatim/api/logging.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/nominatim/api/logging.py b/nominatim/api/logging.py index 351da9a1..6bf3ed38 100644 --- a/nominatim/api/logging.py +++ b/nominatim/api/logging.py @@ -9,6 +9,7 @@ Functions for specialised logging with HTML output. """ from typing import Any, Iterator, Optional, List, Tuple, cast from contextvars import ContextVar +import datetime as dt import textwrap import io @@ -98,11 +99,16 @@ class HTMLLogger(BaseLogger): self.buffer = io.StringIO() + def _timestamp(self) -> None: + self._write(f'

[{dt.datetime.now()}]

') + + def get_buffer(self) -> str: return HTML_HEADER + self.buffer.getvalue() + HTML_FOOTER def function(self, func: str, **kwargs: Any) -> None: + self._timestamp() self._write(f"

Debug output for {func}()

\n

Parameters:

") for name, value in kwargs.items(): self._write(f'
{name}
{self._python_var(value)}
') @@ -110,14 +116,17 @@ class HTMLLogger(BaseLogger): def section(self, heading: str) -> None: + self._timestamp() self._write(f"

{heading}

") def comment(self, text: str) -> None: + self._timestamp() self._write(f"

{text}

") def var_dump(self, heading: str, var: Any) -> None: + self._timestamp() if callable(var): var = var() @@ -125,6 +134,7 @@ class HTMLLogger(BaseLogger): def table_dump(self, heading: str, rows: Iterator[Optional[List[Any]]]) -> None: + self._timestamp() head = next(rows) assert head self._write(f'') @@ -143,6 +153,7 @@ class HTMLLogger(BaseLogger): def result_dump(self, heading: str, results: Iterator[Tuple[Any, Any]]) -> None: """ Print a list of search results generated by the generator function. """ + self._timestamp() def format_osm(osm_object: Optional[Tuple[str, int]]) -> str: if not osm_object: return '-' @@ -173,6 +184,7 @@ class HTMLLogger(BaseLogger): def sql(self, conn: AsyncConnection, statement: 'sa.Executable') -> None: + self._timestamp() sqlstr = self.format_sql(conn, statement) if CODE_HIGHLIGHT: sqlstr = highlight(sqlstr, PostgresLexer(), @@ -348,6 +360,26 @@ HTML_HEADER: str = """ padding: 3pt; border: solid lightgrey 0.1pt } + + table, th, tbody { + border: thin solid; + border-collapse: collapse; + } + td { + border-right: thin solid; + padding-left: 3pt; + padding-right: 3pt; + } + + .timestamp { + font-size: 0.8em; + color: darkblue; + width: calc(100% - 5pt); + text-align: right; + position: absolute; + left: 0; + margin-top: -5px; + } -- 2.39.5
{heading}