From 257c25169a286390d8f1998c2764028e6ef36a40 Mon Sep 17 00:00:00 2001 From: James Higgs Date: Sat, 27 May 2017 19:02:16 +0100 Subject: [PATCH 1/3] Update docs for Record and add example --- src/lib.rs | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index bd02cc4..690b8e5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -528,11 +528,49 @@ impl LevelFilter { } } -/// The "payload" of a log message. This structure is primarily used as a -/// parameter in the [`log`] method of the [`Log`] trait. +/// The "payload" of a log message. /// -/// [`log`]: trait.Log.html#tymethod.log +/// `Record` structures are passed as parameters to the [`log`] method of the +/// [`Log`] trait. Logger implementors manipulate these structures in order to +/// display log messages. `Record`s are automatically created by the [`log!`] +/// macro and so are not seen by log users. +/// +/// Note that the [`level()`] and [`target()`] accessors are equivalent to +/// `self.metadata().level()` and `self.metadata().target()` respectively. +/// These methods are provided as a convenience for users of this structure. +/// +/// # Example +/// +/// The following example shows a simple logger that displays the level, +/// module path, and message of any `Record` that is passed to it. +/// +/// ```rust +/// # extern crate log; +/// struct SimpleLogger; +/// +/// impl log::Log for SimpleLogger { +/// fn enabled(&self, metadata: &log::Metadata) -> bool { +/// true +/// } +/// +/// fn log(&self, record: &log::Record) { +/// if !self.enabled(record.metadata()) { +/// return; +/// } +/// +/// println!("{}:{} -- {}", +/// record.level(), +/// record.location().module_path(), +/// record.args()); +/// } +/// } +/// ``` +/// +/// [`log`]: trait.Log.html#method.log /// [`Log`]: trait.Log.html +/// [`log!`]: macro.log!.html +/// [`level()`]: struct.Record.html#method.level +/// [`target()`]: struct.Record.html#method.target #[derive(Debug)] pub struct Record<'a> { metadata: Metadata<'a>, From fe7f15501acb4cb6d50c4417dd2deecfb55e51c4 Mon Sep 17 00:00:00 2001 From: James Higgs Date: Sat, 27 May 2017 19:36:59 +0100 Subject: [PATCH 2/3] Add a Use header --- src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 690b8e5..1a510b3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -530,6 +530,8 @@ impl LevelFilter { /// The "payload" of a log message. /// +/// # Use +/// /// `Record` structures are passed as parameters to the [`log`] method of the /// [`Log`] trait. Logger implementors manipulate these structures in order to /// display log messages. `Record`s are automatically created by the [`log!`] @@ -539,7 +541,7 @@ impl LevelFilter { /// `self.metadata().level()` and `self.metadata().target()` respectively. /// These methods are provided as a convenience for users of this structure. /// -/// # Example +/// ## Example /// /// The following example shows a simple logger that displays the level, /// module path, and message of any `Record` that is passed to it. From c012469bf27f3197bb9da58819932179ce5a8341 Mon Sep 17 00:00:00 2001 From: James Higgs Date: Sat, 27 May 2017 20:12:32 +0100 Subject: [PATCH 3/3] Change log method link to avoid conflict with Log trait --- src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1a510b3..71f817b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -532,10 +532,10 @@ impl LevelFilter { /// /// # Use /// -/// `Record` structures are passed as parameters to the [`log`] method of the -/// [`Log`] trait. Logger implementors manipulate these structures in order to -/// display log messages. `Record`s are automatically created by the [`log!`] -/// macro and so are not seen by log users. +/// `Record` structures are passed as parameters to the [`log`][method.log] +/// method of the [`Log`] trait. Logger implementors manipulate these +/// structures in order to display log messages. `Record`s are automatically +/// created by the [`log!`] macro and so are not seen by log users. /// /// Note that the [`level()`] and [`target()`] accessors are equivalent to /// `self.metadata().level()` and `self.metadata().target()` respectively. @@ -568,7 +568,7 @@ impl LevelFilter { /// } /// ``` /// -/// [`log`]: trait.Log.html#method.log +/// [method.log]: trait.Log.html#method.log /// [`Log`]: trait.Log.html /// [`log!`]: macro.log!.html /// [`level()`]: struct.Record.html#method.level