diff --git a/examples/custom_default_format.rs b/examples/custom_default_format.rs index d1a45b60..180f198b 100644 --- a/examples/custom_default_format.rs +++ b/examples/custom_default_format.rs @@ -32,7 +32,7 @@ fn init_logger() { builder .default_format_level(false) - .default_format_timestamp_nanos(true); + .default_format_timestamp_nanos(); builder.init(); } diff --git a/src/lib.rs b/src/lib.rs index d3667b87..a02c5842 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -269,11 +269,9 @@ pub mod fmt; pub use self::fmt::glob::*; use self::filter::Filter; -use self::fmt::Formatter; +use self::fmt::{Formatter, TimestampPrecision}; use self::fmt::writer::{self, Writer}; -pub use self::fmt::TimestampPrecision as Timestamp; - /// The default name for the environment variable to read filters from. pub const DEFAULT_FILTER_ENV: &'static str = "RUST_LOG"; @@ -519,28 +517,6 @@ impl Builder { self } - /// Whether or not to write the timestamp in the default format. - #[deprecated = "Use format_timestamp() instead"] - pub fn default_format_timestamp(&mut self, write: bool) -> &mut Self { - if write { - self.format_timestamp(Some(Timestamp::Seconds)); - } else { - self.format_timestamp(None); - } - self - } - - /// Whether or not to write the timestamp with nanosecond precision. - #[deprecated = "Use format_timestamp() instead"] - pub fn default_format_timestamp_nanos(&mut self, write: bool) -> &mut Self { - // The old logic included two booleans: One for timestamp on/off and one - // for nanosecond precision. Mimic it here for compatibility. - if write && self.format.default_format_timestamp.is_some() { - self.format.default_format_timestamp = Some(fmt::TimestampPrecision::Nanos); - } - self - } - /// Configures the amount of spaces to use to indent multiline log records. /// A value of `None` disables any kind of indentation. pub fn default_format_indent(&mut self, indent: Option) -> &mut Self { @@ -549,11 +525,31 @@ impl Builder { } /// Configures if timestamp should be included and in what precision. - pub fn format_timestamp(&mut self, timestamp: Option) -> &mut Self { + pub fn default_format_timestamp(&mut self, timestamp: Option) -> &mut Self { self.format.default_format_timestamp = timestamp; self } + /// Configures the timestamp to use second precision. + pub fn default_format_timestamp_secs(&mut self) -> &mut Self { + self.default_format_timestamp(Some(TimestampPrecision::Seconds)) + } + + /// Configures the timestamp to use millisecond precision. + pub fn default_format_timestamp_millis(&mut self) -> &mut Self { + self.default_format_timestamp(Some(TimestampPrecision::Millis)) + } + + /// Configures the timestamp to use microsecond precision. + pub fn default_format_timestamp_micros(&mut self) -> &mut Self { + self.default_format_timestamp(Some(TimestampPrecision::Micros)) + } + + /// Configures the timestamp to use nanosecond precision. + pub fn default_format_timestamp_nanos(&mut self) -> &mut Self { + self.default_format_timestamp(Some(TimestampPrecision::Nanos)) + } + /// Adds a directive to the filter for a specific module. /// /// # Examples