Skip to content

timestamp_timezone_stamper

CLASS DESCRIPTION
TimezoneAwareTimeStamper

Add a timestamp to event_dict.

TimezoneAwareTimeStamper(
    *,
    fmt: str | Literal["iso"] = "%Y-%m-%dT%H:%M:%S%z",
    key: str = "timestamp",
    now: Callable[[], datetime] = _default_now,
)

Add a timestamp to event_dict.

A workaround for the fact that structlog.processors.TimeStamper only supports UTC or naive (timezone-less) timestamps. Use this if you want to make the timezone explicit in the formatted log message.

PARAMETER DESCRIPTION

strftime format string, or "iso" for ISO 8601 <https://en.wikipedia.org/wiki/ISO_8601>_

TYPE: str | Literal['iso'] DEFAULT: '%Y-%m-%dT%H:%M:%S%z'

Target key in event_dict for added timestamps.

TYPE: str DEFAULT: 'timestamp'

Function that returns the current time when called

TYPE: Callable[[], datetime] DEFAULT: _default_now

Source code in nava/platform/cli/logging/timestamp_timezone_stamper.py
40
41
42
43
44
45
46
47
48
49
def __init__(
    self,
    *,
    fmt: str | Literal["iso"] = "%Y-%m-%dT%H:%M:%S%z",
    key: str = "timestamp",
    now: Callable[[], datetime.datetime] = _default_now,
):
    self.fmt = fmt
    self.key = key
    self.now = now