Skip to content

Commit 7105e63

Browse files
committed
make breaking changes to timestamp API
1 parent 75911d7 commit 7105e63

File tree

2 files changed

+23
-27
lines changed

2 files changed

+23
-27
lines changed

examples/custom_default_format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn init_logger() {
3232

3333
builder
3434
.default_format_level(false)
35-
.default_format_timestamp_nanos(true);
35+
.default_format_timestamp_nanos();
3636

3737
builder.init();
3838
}

src/lib.rs

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,9 @@ pub mod fmt;
269269
pub use self::fmt::glob::*;
270270

271271
use self::filter::Filter;
272-
use self::fmt::Formatter;
272+
use self::fmt::{Formatter, TimestampPrecision};
273273
use self::fmt::writer::{self, Writer};
274274

275-
pub use self::fmt::TimestampPrecision as Timestamp;
276-
277275
/// The default name for the environment variable to read filters from.
278276
pub const DEFAULT_FILTER_ENV: &'static str = "RUST_LOG";
279277

@@ -519,28 +517,6 @@ impl Builder {
519517
self
520518
}
521519

522-
/// Whether or not to write the timestamp in the default format.
523-
#[deprecated = "Use format_timestamp() instead"]
524-
pub fn default_format_timestamp(&mut self, write: bool) -> &mut Self {
525-
if write {
526-
self.format_timestamp(Some(Timestamp::Seconds));
527-
} else {
528-
self.format_timestamp(None);
529-
}
530-
self
531-
}
532-
533-
/// Whether or not to write the timestamp with nanosecond precision.
534-
#[deprecated = "Use format_timestamp() instead"]
535-
pub fn default_format_timestamp_nanos(&mut self, write: bool) -> &mut Self {
536-
// The old logic included two booleans: One for timestamp on/off and one
537-
// for nanosecond precision. Mimic it here for compatibility.
538-
if write && self.format.default_format_timestamp.is_some() {
539-
self.format.default_format_timestamp = Some(fmt::TimestampPrecision::Nanos);
540-
}
541-
self
542-
}
543-
544520
/// Configures the amount of spaces to use to indent multiline log records.
545521
/// A value of `None` disables any kind of indentation.
546522
pub fn default_format_indent(&mut self, indent: Option<usize>) -> &mut Self {
@@ -549,11 +525,31 @@ impl Builder {
549525
}
550526

551527
/// Configures if timestamp should be included and in what precision.
552-
pub fn format_timestamp(&mut self, timestamp: Option<Timestamp>) -> &mut Self {
528+
pub fn default_format_timestamp(&mut self, timestamp: Option<TimestampPrecision>) -> &mut Self {
553529
self.format.default_format_timestamp = timestamp;
554530
self
555531
}
556532

533+
/// Configures the timestamp to use second precision.
534+
pub fn default_format_timestamp_secs(&mut self) -> &mut Self {
535+
self.default_format_timestamp(Some(TimestampPrecision::Seconds))
536+
}
537+
538+
/// Configures the timestamp to use millisecond precision.
539+
pub fn default_format_timestamp_millis(&mut self) -> &mut Self {
540+
self.default_format_timestamp(Some(TimestampPrecision::Millis))
541+
}
542+
543+
/// Configures the timestamp to use microsecond precision.
544+
pub fn default_format_timestamp_micros(&mut self) -> &mut Self {
545+
self.default_format_timestamp(Some(TimestampPrecision::Micros))
546+
}
547+
548+
/// Configures the timestamp to use nanosecond precision.
549+
pub fn default_format_timestamp_nanos(&mut self) -> &mut Self {
550+
self.default_format_timestamp(Some(TimestampPrecision::Nanos))
551+
}
552+
557553
/// Adds a directive to the filter for a specific module.
558554
///
559555
/// # Examples

0 commit comments

Comments
 (0)