From: Sarah Hoffmann Date: Fri, 26 May 2023 07:05:44 +0000 (+0200) Subject: add timestamps to HTML debug output X-Git-Tag: v4.3.0~74^2~9 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/c7db69a30c475db5b5de089c700dd6a581e1de96?ds=sidebyside add timestamps to HTML debug output --- 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; + }
{heading}