Skip to content

Commit

Permalink
make breaking changes to timestamp API
Browse files Browse the repository at this point in the history
  • Loading branch information
KodrAus committed Sep 23, 2019
1 parent 75911d7 commit 7105e63
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
2 changes: 1 addition & 1 deletion examples/custom_default_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn init_logger() {

builder
.default_format_level(false)
.default_format_timestamp_nanos(true);
.default_format_timestamp_nanos();

builder.init();
}
Expand Down
48 changes: 22 additions & 26 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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<usize>) -> &mut Self {
Expand All @@ -549,11 +525,31 @@ impl Builder {
}

/// Configures if timestamp should be included and in what precision.
pub fn format_timestamp(&mut self, timestamp: Option<Timestamp>) -> &mut Self {
pub fn default_format_timestamp(&mut self, timestamp: Option<TimestampPrecision>) -> &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
Expand Down

0 comments on commit 7105e63

Please sign in to comment.