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: ColorThe color to color logs with the Error level.
warn: ColorThe color to color logs with the Warn level.
info: ColorThe color to color logs with the Info level.
debug: ColorThe color to color logs with the Debug level.
trace: ColorThe 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:
ErrorasColor::RedWarnasColor::YellowInfoasColor::WhiteDebugasColor::WhiteTraceasColor::White