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

Add a toggle to enable more precise timestamp #87

Closed
cecton opened this issue May 6, 2018 · 7 comments
Closed

Add a toggle to enable more precise timestamp #87

cecton opened this issue May 6, 2018 · 7 comments

Comments

@cecton
Copy link

cecton commented May 6, 2018

In my application I really need to see the exact time it takes in milliseconds between each log. This will give me an idea if something is slow.

As suggested here, I'm asking if it would be possible to implement a toggle to have it more precise?

@KodrAus
Copy link
Collaborator

KodrAus commented May 6, 2018

Thanks for the suggestion @cecton!

I've kept the timestamp formatting in env_logger intentionally limited so you're stuck with a format that's totally unambiguous.

Being able to increase the precision of that format sounds like a good idea though. We could do something like:

impl Builder {
    // defaults to `false`, like our current format
    fn default_format_timestamp_nanos(yes: bool);
}

impl Formatter {
    fn precise_timestamp(&self) -> PreciseTimestamp;
}

impl Timestamp {
    fn precise(&self) -> PreciseTimestamp {
        PreciseTimestamp(self.0)
    }
}

// Same as Timestamp, but uses a format like 2018-02-14T00:28:07.000000000Z
struct PreciseTimestamp(SystemTime);

So that when you set default_format_timestamp_nanos(true) you get the more precise format. The only problem with this more precise format so far would be that we don't capture it until attempting to write the timestamp, which is fairly deep into the formatting machinery. We should try and capture it sooner.

@cecton
Copy link
Author

cecton commented May 8, 2018

I would gladly try to make a PR if I could but I'm not experienced enough in Rust at the moment to make something good. I will probably give it a try at some point if nobody does before.

Btw, I just thought about something... what about a feature flag? I saw that in the earlier versions of env_logger the logs where more detailed, maybe implementing a feature flag is easier I don't know (I have no idea 😁 )

@KodrAus
Copy link
Collaborator

KodrAus commented May 9, 2018

@cecton I'd be more than happy to help you through a PR if you'd like to give it a shot!

I think managing this through our builders rather than feature flags makes the most sense for env_logger, because we've already got a lot of machinery there around tweaking the format so it's less surprising to find the timestamp precision there too.

@cecton
Copy link
Author

cecton commented May 28, 2018

(I still plan to do it)

@ivan-ochc
Copy link
Contributor

@KodrAus @cecton, hi! I also agree that we need more precise timestamp.
I have a question regarding this issue:
is format 2018-02-14T00:28:07.000000000Z what we need? We can use format_rfc3339_nanos for this purpose. If we want to format nanoseconds like% f,% .3f, etc., seems that it's required much more complicated logic or we can use chrono instead of SystemTime.

@KodrAus
Copy link
Collaborator

KodrAus commented Jul 22, 2018

@ivan-ochc If I understand correctly you're asking if the RFC3339 format with nanos is the right one for us to use? I think it's the most appropriate format for our high-precision timestamp that means we can stick with humantime and avoid depending on chrono, which we recently removed.

@KodrAus
Copy link
Collaborator

KodrAus commented Aug 13, 2018

This was released in 0.5.12 🎉

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

No branches or pull requests

3 participants