Skip to content

Changing TimeStamper key to "ts" breaks ordering of logs for ConsoleRenderer #541

@macintacos

Description

@macintacos

The following code:

import structlog

structlog.configure(
    processors=[
        structlog.processors.TimeStamper(fmt="iso", key="ts"),
        structlog.stdlib.add_log_level,
        structlog.dev.ConsoleRenderer(),
    ],
    logger_factory=structlog.PrintLoggerFactory(),
)

logger = structlog.get_logger()

logger.info("Testing!")

Produces the following logs. Note that ts is at the end, instead of the beginning, where I would've expected.

[info     ] Testing!                       ts=2023-08-18T21:53:56.587146Z

If I remove the key parameter from the TimeStamper (structlog.processors.TimeStamper(fmt="iso")), the timestamp properly moves to the beginning, as I would expect:

2023-08-18T21:54:50.018921Z [info     ] Testing!

Considering that the key parameter is built-into TimeStamper, could ConsoleRenderer be updated to properly render the timestamp where it's supposed to be if you change the key?

I'm also not completely convinced I'm not just doing something wrong, so any help would be appreciated. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions