Feature request: specify timestamp format
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.
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.
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?