-
Notifications
You must be signed in to change notification settings - Fork 31
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 Configuration for Higher Time Precision with Decimals #68
Add Configuration for Higher Time Precision with Decimals #68
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some style nits, then this lgtm
src/lib.rs
Outdated
let start = match ctx.current_span().id() { | ||
Some(id) => match ctx.span(id) { | ||
// if the event is in a span, get the span's starting point. | ||
Some(ctx) => { | ||
let ext = ctx.extensions(); | ||
let data = ext | ||
.get::<Data>() | ||
.expect("Data cannot be found in extensions"); | ||
Some(data.start) | ||
} | ||
None => None, | ||
}, | ||
None => None, | ||
}; | ||
if let Some(start) = start { | ||
let elapsed = start.elapsed(); | ||
let millis = elapsed.as_millis(); | ||
let secs = elapsed.as_secs(); | ||
let (n, unit) = if millis < 1000 { | ||
(millis as _, "ms") | ||
} else if secs < 60 { | ||
(secs, "s ") | ||
} else { | ||
(secs / 60, "m ") | ||
}; | ||
let n = format!("{n:>3}"); | ||
write!( | ||
&mut event_buf, | ||
"{timestamp}{unit} ", | ||
timestamp = self.styled(Style::new().dimmed(), n), | ||
unit = self.styled(Style::new().dimmed(), unit), | ||
) | ||
.expect("Unable to write to buffer"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip for the future: when moving things out into a new function, do that in a separate commit, and then modify it in other commits. This makes it easier to track for reviewers to see what changes you made in detail
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the advice. Will separate commits for clarity moving forward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, unfortunately you also need to rebase over the latest changes
Resolve merge conflicts in src/lib.rs and src/format.rs during rebase
…ion" changes. Rebased to resolve merge conflicts and updated PR to match changes in commit 8ccafe8 by @ten3roberts. The commit simplifies how Span's Extensions is retrieved.
59c8121
to
4c66dca
Compare
Hi @oli-obk Lines 476 to 487 in 8aa51bc
I've adjusted this PR accordingly in 4c66dca. |
Thanks! |
To address #67, add a new configuration option,
with_higher_precision
. When this option is enabled, the time is displayed with higher precision, including decimal points.with_higher_precision
as a configuration option.on_event
method to separate methods for code reusability1Example Output:
With
higher_precision enabled
, the output will look like this.Footnotes
If this PR looks good, I'd like to propose an implementation to address Issue 17 based on this as a foundation. ↩