forked from emabee/flexi_logger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce AdaptiveFormat to improve color handling.
- Support using atty without provided coloring - Extend example colors to provide insight in how AdaptiveFormat works - Remove deprecated method `Logger::do_not-log()` (use `log_target()` with `LogTarget::DevNull` instead). - Remove deprecated method `Logger::o_log_to_file()` (use `log_target()` instead). The clearer convenience method `Logger::log_to_file()` is still available.
- Loading branch information
Showing
8 changed files
with
320 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "flexi_logger" | ||
version = "0.15.13" | ||
version = "0.16.0-alpha" | ||
authors = ["emabee <[email protected]>"] | ||
edition = "2018" | ||
license = "MIT OR Apache-2.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,75 @@ | ||
fn main() { | ||
#[cfg(not(feature = "colors"))] | ||
println!("Feature color is switched off"); | ||
|
||
#[cfg(feature = "colors")] | ||
for i in 0..=255 { | ||
println!("{}: {}", i, yansi::Paint::fixed(i, i)); | ||
{ | ||
use atty::Stream::{Stderr, Stdout}; | ||
use yansi::{Color, Paint, Style}; | ||
|
||
for i in 0..=255 { | ||
println!("{}: {}", i, Paint::fixed(i, i)); | ||
} | ||
|
||
println!(""); | ||
|
||
if atty::is(Stdout) { | ||
println!( | ||
"Stdout is considered a tty - \ | ||
flexi_logger::AdaptiveFormat will use colors", | ||
); | ||
} else { | ||
println!( | ||
"Stdout is not considered a tty - \ | ||
flexi_logger::AdaptiveFormat will NOT use colors" | ||
); | ||
} | ||
|
||
if atty::is(Stderr) { | ||
println!( | ||
"Stderr is considered a tty - \ | ||
flexi_logger::AdaptiveFormat will use colors", | ||
); | ||
} else { | ||
println!( | ||
"Stderr is not considered a tty - \ | ||
flexi_logger::AdaptiveFormat will NOT use colors!" | ||
); | ||
} | ||
|
||
// Enable ASCII escape sequence support on Windows consoles, | ||
// but disable coloring on unsupported Windows consoles | ||
if cfg!(windows) { | ||
if !Paint::enable_windows_ascii() { | ||
println!("unsupported windows console detected => coloring disabled"); | ||
Paint::disable(); | ||
return; | ||
} | ||
} | ||
|
||
println!( | ||
"\n{}", | ||
Style::new(Color::Fixed(196)) | ||
.bold() | ||
.paint("This is red output like by default with err!") | ||
); | ||
println!( | ||
"{}", | ||
Style::new(Color::Fixed(208)) | ||
.bold() | ||
.paint("This is yellow output like by default with warn!") | ||
); | ||
println!( | ||
"{}", | ||
Style::new(Color::Unset).paint("This is normal output like by default with info!") | ||
); | ||
println!( | ||
"{}", | ||
Style::new(Color::Fixed(7)).paint("This is output like by default with debug!") | ||
); | ||
println!( | ||
"{}", | ||
Style::new(Color::Fixed(8)).paint("This is grey output like by default with trace!") | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.