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

Feature request: specify timestamp format #44

Open
crusty-dave opened this issue Jun 8, 2021 · 2 comments
Open

Feature request: specify timestamp format #44

crusty-dave opened this issue Jun 8, 2021 · 2 comments

Comments

@crusty-dave
Copy link

I cannot seem to find any way to do this with slog / sloggers. In log4rs I can do the following:

        // Logging to log file.
        let rolling_appender = match RollingFileAppender::builder()
            // Pattern: https://docs.rs/log4rs/*/log4rs/encode/pattern/index.html
            .encoder(Box::new(PatternEncoder::new(
                "{d(%Y-%m-%dT%H:%M:%S%.3f)} {t} {l} - {m}{n}",
            )))
            .build(&self.log_path, Box::new(compound_policy))
        {
            Ok(appender) => appender,
            Err(e) => {
                return Err(format! {"rolling log builder failed, error {:?}", e});
            }
        };

I would really like to be able to store timestamps as the equivalent of the following:

time.to_rfc3339_opts(SecondsFormat::Millis, true)

I didn't see any way to do this, my apologies if I missed it.

Thanks in advance.

@sile
Copy link
Owner

sile commented Jun 13, 2021

Though sloggers currently doesn't provide this feature, slog has a way to customize the timestamp format (e.g., slog_term::CompactFormatBuilder.use_custom_timestamp), so it seems not hard to implement it in sloggers.
Please let me consider whether the implementation is actually possible.

@sile
Copy link
Owner

sile commented Jun 13, 2021

After considering the above possibility, it turned out that it's difficult to allow users to specify arbitrary timestamp format in the current slog and sloggers designs.
However, it could be possible to add specific predefined formats (e.g., RFC3339) to the available list. Does it satisfy your requirements?

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