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

logs with rfc3339 time have no consistent length #133

Open
cscherrNT opened this issue Aug 1, 2023 · 2 comments
Open

logs with rfc3339 time have no consistent length #133

cscherrNT opened this issue Aug 1, 2023 · 2 comments

Comments

@cscherrNT
Copy link

The width of the rfc3339 timestamp does not guarantee a fixed length, only that at least one digit in the subsecond part is present.

2023-08-01T11:10:57.758299073Z [WARN] trying to reinitialize the logger, ignoring
2023-08-01T11:10:57.75835825Z [WARN] trying to reinitialize the logger, ignoring
2023-08-01T11:10:57.75838119Z [WARN] trying to reinitialize the logger, ignoring
2023-08-01T11:10:57.758438693Z [WARN] trying to reinitialize the logger, ignoring
2023-08-01T11:10:57.758461685Z [INFO] Successfully ignored extra init

I generate a config like this:

let config = simplelog::ConfigBuilder::new()
    .set_time_format_rfc3339()
    .build();

Proposed fix: Add a config that enables padding for the timestamp.

Example:

let config = simplelog::ConfigBuilder::new()
    .set_time_format_rfc3339()
    .set_time_padding(simplelog::TimePadding::Right)
    .build();
2023-08-01T11:10:57.758299073Z [WARN] trying to reinitialize the logger, ignoring
2023-08-01T11:10:57.75835825Z  [WARN] trying to reinitialize the logger, ignoring
2023-08-01T11:10:57.75838119Z  [WARN] trying to reinitialize the logger, ignoring
2023-08-01T11:10:57.758438693Z [WARN] trying to reinitialize the logger, ignoring
2023-08-01T11:10:57.758461685Z [INFO] Successfully ignored extra init

Alternatively, show the zeros, or dont show subseconds at all

As I understand it rfc3339 would also allow it to show the zeros or not to show subseconds at all (like in the examples section).

let config = simplelog::ConfigBuilder::new()
    .set_time_format_rfc3339()
    .set_time_padding(simplelog::TimePadding::ShowZeros)
    .build();
2023-08-01T11:10:57.758299073Z [WARN] trying to reinitialize the logger, ignoring
2023-08-01T11:10:57.758358250Z [WARN] trying to reinitialize the logger, ignoring
2023-08-01T11:10:57.758381190Z [WARN] trying to reinitialize the logger, ignoring
2023-08-01T11:10:57.758438693Z [WARN] trying to reinitialize the logger, ignoring
2023-08-01T11:10:57.758461685Z [INFO] Successfully ignored extra init
@Drakulix
Copy link
Owner

Drakulix commented Aug 1, 2023

Seems very reasonable.

I am happy to review and merge pull requests implementing any or all of the proposed solutions.

@cscherrNT
Copy link
Author

I implemented a possible fix in #134

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