Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
macintacos opened this issue Aug 18, 2023 · 3 comments

Comments

@macintacos
Copy link

macintacos commented Aug 18, 2023

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!

@hynek
Copy link
Owner

hynek commented Aug 19, 2023

I suspect we need to add a “timestamp” argument to ConsoleLogger, like we have for renamed “event”

@macintacos
Copy link
Author

Just curious - if I were to attempt a fix for this, are you planning a release anytime soon?

@hynek hynek closed this as completed in 25c361c Sep 7, 2023
@hynek
Copy link
Owner

hynek commented Sep 7, 2023

I will try to get out a soonish release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants