add TimePadding with Right and AddZeros#134
add TimePadding with Right and AddZeros#134cscherrNT wants to merge 1 commit intoDrakulix:masterfrom
TimePadding with Right and AddZeros#134Conversation
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.
Maybe make the 30 into a constant?
Drakulix
left a comment
There was a problem hiding this comment.
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!
| 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.
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.
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.
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.
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.
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 { |
This is a proposed fix for #133.
I added a
TimePaddingEnum. inwrite_time, the formatted time stamp is generated with thetimemodule like before, then I do some formatting.TimePadding::Rightjust applys an offset to the timestamp, like other paddings.TimePadding::AddZerosadds zeros to the Timestamp, accodring to it's length. (only with rfc3339 formatting)Usage
Build a
Configlike this:Example output:
Note: This is my first Pull Request, I hope I didn't miss anything important.