1

Swap out color backend

This commit is contained in:
Evan Pratten 2023-07-20 10:57:17 -04:00
parent 77266548c8
commit b76a6e1291
3 changed files with 26 additions and 12 deletions

View File

@ -18,19 +18,19 @@ protomask-tun = { path = "protomask-tun", version = "0.1.0" }
tokio = { version = "1.29.1", features = [
"macros",
"rt-multi-thread",
"process",
# "process",
"sync"
] }
clap = { version = "4.3.11", features = ["derive"] }
serde = { version = "1.0.171", features = ["derive"] }
ipnet = { version = "2.8.0", features = ["serde"] }
hyper = { version = "0.14.27", features = ["server", "http1", "tcp"] }
owo-colors = { version = "3.5.0", features = ["supports-colors"] }
toml = "0.7.6"
log = "0.4.19"
fern = "0.6.2"
serde_path_to_error = "0.1.13"
thiserror = "1.0.43"
colored = "2.0.4"
tun-tap = "0.1.3"
bimap = "0.6.3"
pnet_packet = "0.33.0"

View File

@ -6,7 +6,6 @@ use std::{
time::Duration,
};
use colored::Colorize;
use ipnet::{Ipv4Net, Ipv6Net};
/// A static mapping rule
@ -74,8 +73,8 @@ impl Config {
Err(e) => {
eprintln!(
"Failed to parse config file due to:\n {}\n at {}",
e.inner().message().bright_red(),
e.path().to_string().bright_cyan()
e.inner().message(),
e.path()
);
std::process::exit(1);
}

View File

@ -1,4 +1,4 @@
use colored::Colorize;
use owo_colors::{OwoColorize, Stream::Stdout};
/// Enable the logger
#[allow(dead_code)]
@ -11,18 +11,33 @@ pub fn enable_logger(verbose: bool) {
"{}{}",
// Level messages are padded to keep the output looking somewhat sane
match record.level() {
log::Level::Error => "ERROR".red().bold().to_string(),
log::Level::Warn => "WARN ".yellow().bold().to_string(),
log::Level::Info => "INFO ".green().bold().to_string(),
log::Level::Debug => "DEBUG".bright_blue().bold().to_string(),
log::Level::Trace => "TRACE".bright_white().bold().to_string(),
log::Level::Error => "ERROR"
.if_supports_color(Stdout, |text| text.red())
.if_supports_color(Stdout, |text| text.bold())
.to_string(),
log::Level::Warn => "WARN "
.if_supports_color(Stdout, |text| text.yellow())
.if_supports_color(Stdout, |text| text.bold())
.to_string(),
log::Level::Info => "INFO "
.if_supports_color(Stdout, |text| text.green())
.if_supports_color(Stdout, |text| text.bold())
.to_string(),
log::Level::Debug => "DEBUG"
.if_supports_color(Stdout, |text| text.bright_blue())
.if_supports_color(Stdout, |text| text.bold())
.to_string(),
log::Level::Trace => "TRACE"
.if_supports_color(Stdout, |text| text.bright_white())
.if_supports_color(Stdout, |text| text.bold())
.to_string(),
},
// Only show the outer package name if verbose logging is enabled (otherwise nothing)
match verbose {
true => format!(" [{}]", record.target().split("::").nth(0).unwrap()),
false => String::new(),
}
.bright_black()
.if_supports_color(Stdout, |text| text.bright_black())
),
message
))