Skip to content

logs with rfc3339 time have no consistent length #133

@cscherrNT

Description

@cscherrNT

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions