Changed logging to use termcolor crate to fix ansi control codes showing when run under Windows Command Prompt

This commit is contained in:
Ben Wallis 2020-12-06 14:41:59 +00:00
parent 115c09120d
commit 81a8ee0c19
5 changed files with 18 additions and 2 deletions

11
Cargo.lock generated
View File

@ -4714,6 +4714,15 @@ dependencies = [
"xattr",
]
[[package]]
name = "termcolor"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
dependencies = [
"winapi-util",
]
[[package]]
name = "textwrap"
version = "0.11.0"
@ -5441,6 +5450,7 @@ dependencies = [
"ron",
"serde",
"signal-hook",
"termcolor",
"tracing",
"tracing-subscriber",
"tracing-tracy",
@ -5495,6 +5505,7 @@ dependencies = [
"serde",
"specs",
"specs-idvs",
"termcolor",
"tracing",
"tracing-appender",
"tracing-log",

View File

@ -18,6 +18,7 @@ clap = "2.33"
crossterm = "0.17"
lazy_static = "1"
signal-hook = "0.1.16"
termcolor = "1.1"
tracing = { version = "0.1", default-features = false }
tracing-subscriber = { version = "0.2.3", default-features = false, features = ["env-filter", "fmt", "chrono", "ansi", "smallvec"] }
ron = {version = "0.6", default-features = false}

View File

@ -1,4 +1,5 @@
use crate::tuilog::TuiLog;
use termcolor::{ColorChoice, StandardStream};
use tracing::Level;
use tracing_subscriber::{filter::LevelFilter, EnvFilter, FmtSubscriber};
#[cfg(feature = "tracy")]
@ -55,7 +56,7 @@ pub fn init(basic: bool) {
.with_env_filter(filter);
if basic {
subscriber.init();
subscriber.with_writer(|| StandardStream::stdout(ColorChoice::Auto)).init();
} else {
subscriber.with_writer(|| LOG.clone()).init();
}

View File

@ -90,6 +90,7 @@ itertools = "0.9.0"
tracing-tracy = { version = "0.3.0", optional = true }
# Logging
termcolor = "1.1"
tracing = "0.1"
tracing-appender = "0.1"
tracing-log = "0.1.1"

View File

@ -2,6 +2,7 @@ use std::fs;
use crate::settings::Settings;
use termcolor::{ColorChoice, StandardStream};
use tracing::{debug, error, info, trace};
use tracing_subscriber::{filter::LevelFilter, prelude::*, registry, EnvFilter};
@ -71,7 +72,8 @@ pub fn init(settings: &Settings) -> Vec<impl Drop> {
let filter = base_exceptions(EnvFilter::new("")).add_directive(LevelFilter::TRACE.into());
// Create the terminal writer layer.
let (non_blocking, _stdio_guard) = tracing_appender::non_blocking(std::io::stdout());
let (non_blocking, _stdio_guard) =
tracing_appender::non_blocking(StandardStream::stdout(ColorChoice::Auto));
_guards.push(_stdio_guard);
// Try to create the log file's parent folders.