forked from amethyst/amethyst
-
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.
Add start_logger function and support for color output
- Loading branch information
Showing
4 changed files
with
42 additions
and
19 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use std::io; | ||
|
||
use fern; | ||
use log::LevelFilter; | ||
|
||
/// Starts a basic logger outputting to stdout with color on supported platforms. | ||
/// | ||
/// If you do not intend on using the logger builtin to Amethyst, it's highly recommended you | ||
/// initialise your own. | ||
pub fn start_logger() { | ||
let color_config = fern::colors::ColoredLevelConfig::new(); | ||
|
||
fern::Dispatch::new() | ||
.format(move |out, message, record| { | ||
out.finish(format_args!( | ||
"{color}[{level}][{target}] {message}{color_reset}", | ||
color = format_args!( | ||
"\x1B[{}m", | ||
color_config.get_color(&record.level()).to_fg_str() | ||
), | ||
level = record.level(), | ||
target = record.target(), | ||
message = message, | ||
color_reset = "\x1B[0m" | ||
)) | ||
}) | ||
.level(LevelFilter::Debug) | ||
.chain(io::stdout()) | ||
.apply() | ||
.unwrap_or_else(|_| { | ||
debug!("Global logger already set, default Amethyst logger will not be used") | ||
}); | ||
} |