Skip to content

Commit

Permalink
chore(cli): Replace fern logging implementation with tracing
Browse files Browse the repository at this point in the history
No point in keeping two implementations around
  • Loading branch information
theduke committed Mar 7, 2023
1 parent f6a88f6 commit cb31c51
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 75 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions lib/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ distance = "0.4"
# For the inspect subcommand
bytesize = "1.0"
cfg-if = "1.0"
# For debug feature
fern = { version = "0.6", features = ["colored"], optional = true }
tempfile = "3.4.0"
http_req = { version="^0.8", default-features = false, features = ["rust-tls"] }
reqwest = { version = "^0.11", default-features = false, features = ["rustls-tls", "json", "multipart"] }
Expand Down Expand Up @@ -166,7 +164,7 @@ llvm = [
"wasmer-compiler-llvm",
"compiler",
]
debug = ["fern", "wasmer-wasi/logging"]
debug = ["tracing", "wasmer-wasi/logging"]
disable-all-logging = ["wasmer-wasi/disable-all-logging", "log/release_max_level_off"]
headless = []
headless-minimal = ["headless", "disable-all-logging", "wasi"]
Expand Down
72 changes: 1 addition & 71 deletions lib/cli/src/logging.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Logging functions for the debug feature.
/// Subroutine to instantiate the loggers
#[cfg(feature = "tracing")]
#[cfg(any(feature = "tracing", feature = "debug"))]
pub fn set_up_logging(verbose: u8) -> Result<(), String> {
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, EnvFilter};
Expand All @@ -26,73 +26,3 @@ pub fn set_up_logging(verbose: u8) -> Result<(), String> {

Ok(())
}

/// Subroutine to instantiate the loggers
#[deprecated("please use the tracing feature instead")]
#[cfg(not(feature = "tracing"))]
pub fn set_up_logging(verbose: u8) -> Result<(), String> {
use crate::utils::wasmer_should_print_color;
use anyhow::Result;
use fern::colors::{Color, ColoredLevelConfig};
use std::time;

/// The debug level
pub type DebugLevel = log::LevelFilter;

let colors_line = ColoredLevelConfig::new()
.error(Color::Red)
.warn(Color::Yellow)
.trace(Color::BrightBlack);
let should_color = wasmer_should_print_color();

let colors_level = colors_line.info(Color::Green);
let level = match verbose {
1 => DebugLevel::Debug,
_ => DebugLevel::Trace,
};
let dispatch = fern::Dispatch::new()
.level(level)
.chain({
let base = if should_color {
fern::Dispatch::new().format(move |out, message, record| {
let time = time::SystemTime::now().duration_since(time::UNIX_EPOCH).expect("Can't get time");
out.finish(format_args!(
"{color_line}[{seconds}.{millis} {level} {target}{color_line}]{ansi_close} {message}",
color_line = format_args!(
"\x1B[{}m",
colors_line.get_color(&record.level()).to_fg_str()
),
seconds = time.as_secs(),
millis = time.subsec_millis(),
level = colors_level.color(record.level()),
target = record.target(),
ansi_close = "\x1B[0m",
message = message,
));
})
} else {
// default formatter without color
fern::Dispatch::new().format(move |out, message, record| {
let time = time::SystemTime::now().duration_since(time::UNIX_EPOCH).expect("Can't get time");
out.finish(format_args!(
"[{seconds}.{millis} {level} {target}] {message}",
seconds = time.as_secs(),
millis = time.subsec_millis(),
level = record.level(),
target = record.target(),
message = message,
));
})
};

base
.filter(|metadata| {
metadata.target().starts_with("wasmer")
})
.chain(std::io::stdout())
});

dispatch.apply().map_err(|e| format!("{}", e))?;

Ok(())
}

0 comments on commit cb31c51

Please sign in to comment.