Expand description
A simple configurable logger with format specification.
This crate provides an implementation of log crate, which
provides integrated logging interface.
§Examples
§Basic
#[macro_use]
extern crate log;
extern crate fmtlog;
fn main() {
fmtlog::default().set().unwrap();
info!("Hello!"); // INFO: Hello!
}See also the function default.
§Configure in Code
#[macro_use]
extern crate log;
extern crate fmtlog;
use fmtlog::{Config, LevelFilter};
fn main() {
fmtlog::new(Config::new().level(LevelFilter::Trace))
.set()
.unwrap();
info!("Hello!"); // INFO: Hello!
}See also the struct Config.
§Format Specification
The format string is basically a string, but the following specifiers will converted into another string.
| Spec. | Example | Description |
|---|---|---|
%% | Literal %. | |
%} | Literal }. (use in {}.) | |
%N | hyper | The target of the log. |
%f | main.rs | The file that the log defined. |
%S | main.rs:15 | The file and line that the log defined. |
%M | An error has occured. | The log message. |
%l | info | The log level. (lowercase) |
%L | INFO | The log level. (uppercase) |
%T(<format>) | %T(%D %T) -> 01/01/21 12:00:00 | The local time. (see chrono’s format specification). Requires feature: chrono |
%U(<format>) | %T(%D %T) -> 01/01/21 12:00:00 | The UTC time. (see chrono’s format specification). Requires feature: chrono |
%F(<color>){...} | Set the foreground color. Requires feature: colored | |
%F(<error>,<warn>,<info>,<debug>,<trace>){...} | Set the foreground color. (Branch by the log level.) Requires feature: colored | |
%B(<color>){...} | Set the background color. Requires feature: colored | |
%B(<error>,<warn>,<info>,<debug>,<trace>){...} | Set the background color. (Branch by the log level.) Requires feature: colored | |
%b{...} | Bold the text. Requires feature: colored | |
%d{...} | Dim the text color. Requires feature: colored | |
%i{...} | Print the text in italics. Requires feature: colored | |
%r{...} | Reverse the foreground and background color. Requires feature: colored | |
%u{...} | Underline the text. Requires feature: colored | |
%s{...} | Strikethrough the text. Requires feature: colored |
§Supported Color (Requires feature: colored)
All supported color used by %C and %O is here.
blackredgreenyellowbluemagenta(=purple)cyanwhitebright blackbright redbright greenbright yellowbright bluebright magentabright cyanbright white#ffffff(Hexadecimal RGB)
Modules§
- formats
- Formats Collection (See the document.)
Structs§
Enums§
- Colorize
- Colorize the output
- Level
Filter - An enum representing the available verbosity level filters of the logger.
- Output
- The Output type