99//!
1010//! The format used to print log records can be customised using the [`Builder::format`]
1111//! method.
12- //! Custom formats can apply different color and weight to printed values using
13- //! [`Style`] builders.
12+ //!
13+ //! Terminal styling is done through ANSI escape codes and will be adapted to the capabilities of
14+ //! the target stream.
15+ //! For example, you could use one of:
16+ //! - [anstyle](https://docs.rs/anstyle) is a minimal, runtime string styling API and is re-exported as [`style`]
17+ //! - [owo-colors](https://docs.rs/owo-colors) is a feature rich runtime string styling API
18+ //! - [color-print](https://docs.rs/color-print) for feature-rich compile-time styling API
19+ //! See also [`Formatter::default_level_style`]
1420//!
1521//! ```
1622//! use std::io::Write;
2430//! });
2531//! ```
2632//!
27- //! [`Formatter`]: struct.Formatter.html
28- //! [`Style`]: struct.Style.html
29- //! [`Builder::format`]: ../struct.Builder.html#method.format
30- //! [`Write`]: https://doc.rust-lang.org/stable/std/io/trait.Write.html
33+ //! [`Builder::format`]: crate::Builder::format
34+ //! [`Write`]: std::io::Write
3135
3236use std:: cell:: RefCell ;
3337use std:: fmt:: Display ;
@@ -80,7 +84,7 @@ impl Default for TimestampPrecision {
8084/// A formatter to write logs into.
8185///
8286/// `Formatter` implements the standard [`Write`] trait for writing log records.
83- /// It also supports terminal colors, through the [`style`] method .
87+ /// It also supports terminal styling using ANSI escape codes .
8488///
8589/// # Examples
8690///
@@ -95,9 +99,8 @@ impl Default for TimestampPrecision {
9599/// builder.format(|buf, record| writeln!(buf, "{}: {}", record.level(), record.args()));
96100/// ```
97101///
98- /// [`Write`]: https://doc.rust-lang.org/stable/std/io/trait.Write.html
99- /// [`writeln`]: https://doc.rust-lang.org/stable/std/macro.writeln.html
100- /// [`style`]: #method.style
102+ /// [`Write`]: std::io::Write
103+ /// [`writeln`]: std::writeln
101104pub struct Formatter {
102105 buf : Rc < RefCell < Buffer > > ,
103106 write_style : WriteStyle ,
@@ -129,6 +132,8 @@ impl Formatter {
129132 /// Get the default [`style::Style`] for the given level.
130133 ///
131134 /// The style can be used to print other values besides the level.
135+ ///
136+ /// See [`style`] for how to adapt it to the styling crate of your choice
132137 pub fn default_level_style ( & self , level : Level ) -> style:: Style {
133138 if self . write_style == WriteStyle :: Never {
134139 style:: Style :: new ( )
@@ -238,10 +243,6 @@ type SubtleStyle = StyledValue<&'static str>;
238243type SubtleStyle = & ' static str ;
239244
240245/// A value that can be printed using the given styles.
241- ///
242- /// It is the result of calling [`Style::value`].
243- ///
244- /// [`Style::value`]: struct.Style.html#method.value
245246#[ cfg( feature = "color" ) ]
246247struct StyledValue < T > {
247248 style : style:: Style ,
@@ -251,14 +252,13 @@ struct StyledValue<T> {
251252#[ cfg( feature = "color" ) ]
252253impl < T : std:: fmt:: Display > std:: fmt:: Display for StyledValue < T > {
253254 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
254- let style = self . style . render ( ) ;
255- let reset = self . style . render_reset ( ) ;
255+ let style = self . style ;
256256
257257 // We need to make sure `f`s settings don't get passed onto the styling but do get passed
258258 // to the value
259259 write ! ( f, "{style}" ) ?;
260260 self . value . fmt ( f) ?;
261- write ! ( f, "{reset }" ) ?;
261+ write ! ( f, "{style:# }" ) ?;
262262 Ok ( ( ) )
263263 }
264264}
0 commit comments