-
Notifications
You must be signed in to change notification settings - Fork 73
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 TimePadding
with Right
and AddZeros
#134
base: master
Are you sure you want to change the base?
Conversation
only do timepadding for rfc3339 fix a doc comment
// | ||
// the rfc3339 timestamp is 30 characters long, if it would not end with a 0 in the | ||
// subseconds part. To fix this inconsistency, we add zeros before the Z. | ||
while formatted.len() < 30 { |
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.
Maybe make the 30 into a constant?
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.
Good idea
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.
This looks like a really solid start.
A couple of smaller remarks and also please add your changes in the Unreleased
section of the CHANGELOG.md
. Otherwise very good job!
@@ -345,6 +363,7 @@ impl Default for Config { | |||
module: LevelFilter::Off, | |||
time_format: TimeFormat::Custom(format_description!("[hour]:[minute]:[second]")), | |||
time_offset: UtcOffset::UTC, | |||
time_padding: TimePadding::AddZeros, |
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.
I think this modifies the current default (of no padding), which I would want to release as a minor version. Can we maybe consider this to be Off
by default?
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.
Leaving the padding as Off
is certainly possible, but I would argue that setting a padding by default would improve usability a little.
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.
I agree, but then we will need a new major version.
Err(err) => panic!("Invalid time format: {}", err), | ||
_ => {} | ||
let mut formatted: String = | ||
formatted.unwrap_or_else(|err| panic!("Invalid time format: {}", err)); |
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.
I think this drops the special casing for Format::StdIo
, you should be able to use assign using the match here instead.
formatted.unwrap_or_else(|err| panic!("Invalid time format: {}", err)); | |
match formatted { | |
Ok(res) => res, | |
Err(Format::StdIo(err)) => return Err(err), | |
Err(err) => panic!("Invalid time format: {}", err), | |
}; |
// subseconds part. To fix this inconsistency, we add zeros before the Z. | ||
while formatted.len() < 30 { | ||
formatted.insert(formatted.len() - 1, '0') | ||
} |
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.
I feel like this is not very performant and there should be a way to not add the zeros one by one.
// | ||
// the rfc3339 timestamp is 30 characters long, if it would not end with a 0 in the | ||
// subseconds part. To fix this inconsistency, we add zeros before the Z. | ||
while formatted.len() < 30 { |
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.
Good idea
This is a proposed fix for #133.
I added a
TimePadding
Enum. inwrite_time
, the formatted time stamp is generated with thetime
module like before, then I do some formatting.TimePadding::Right
just applys an offset to the timestamp, like other paddings.TimePadding::AddZeros
adds zeros to the Timestamp, accodring to it's length. (only with rfc3339 formatting)Usage
Build a
Config
like this:Example output:
Note: This is my first Pull Request, I hope I didn't miss anything important.