Struct fern::colors::ColoredLevelConfig
source · pub struct ColoredLevelConfig {
pub error: Color,
pub warn: Color,
pub info: Color,
pub debug: Color,
pub trace: Color,
}
Expand description
Configuration specifying colors a log level can be colored as.
Example usage setting custom ‘info’ and ‘debug’ colors:
use fern::colors::{Color, ColoredLevelConfig};
let colors = ColoredLevelConfig::new()
.info(Color::Green)
.debug(Color::Magenta);
fern::Dispatch::new()
.format(move |out, message, record| {
out.finish(format_args!(
"[{}] {}",
colors.color(record.level()),
message
))
})
.chain(std::io::stdout())
.apply()?;
Fields§
§error: Color
The color to color logs with the Error
level.
warn: Color
The color to color logs with the Warn
level.
info: Color
The color to color logs with the Info
level.
debug: Color
The color to color logs with the Debug
level.
trace: Color
The color to color logs with the Trace
level.
Implementations§
source§impl ColoredLevelConfig
impl ColoredLevelConfig
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new ColoredLevelConfig with the default colors.
This matches the behavior of ColoredLevelConfig::default
.
sourcepub fn error(self, error: Color) -> Self
pub fn error(self, error: Color) -> Self
Overrides the Error
level color with the given color.
The default color is Color::Red
.
sourcepub fn warn(self, warn: Color) -> Self
pub fn warn(self, warn: Color) -> Self
Overrides the Warn
level color with the given color.
The default color is Color::Yellow
.
sourcepub fn info(self, info: Color) -> Self
pub fn info(self, info: Color) -> Self
Overrides the Info
level color with the given color.
The default color is Color::White
.
sourcepub fn debug(self, debug: Color) -> Self
pub fn debug(self, debug: Color) -> Self
Overrides the Debug
level color with the given color.
The default color is Color::White
.
sourcepub fn trace(self, trace: Color) -> Self
pub fn trace(self, trace: Color) -> Self
Overrides the Trace
level color with the given color.
The default color is Color::White
.
sourcepub fn color(&self, level: Level) -> WithFgColor<Level>
pub fn color(&self, level: Level) -> WithFgColor<Level>
Colors the given log level with the color in this configuration corresponding to it’s level.
The structure returned is opaque, but will print the Level surrounded
by ANSI color codes when displayed. This will work correctly for
UNIX terminals, but due to a lack of support from the colored
crate, this will not function in Windows.
Trait Implementations§
source§impl Clone for ColoredLevelConfig
impl Clone for ColoredLevelConfig
source§fn clone(&self) -> ColoredLevelConfig
fn clone(&self) -> ColoredLevelConfig
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Default for ColoredLevelConfig
impl Default for ColoredLevelConfig
source§fn default() -> Self
fn default() -> Self
Retrieves the default configuration. This has:
Error
asColor::Red
Warn
asColor::Yellow
Info
asColor::White
Debug
asColor::White
Trace
asColor::White