diff options
author | boasting-squirrel <boasting.squirrel@gmail.com> | 2019-03-13 18:30:54 +0000 |
---|---|---|
committer | boasting-squirrel <boasting.squirrel@gmail.com> | 2019-03-13 18:30:54 +0000 |
commit | 17ef61a126e81c9ecfd1ebdd89537e854a06cae6 (patch) | |
tree | 24669a4d54650bd6b114012d3b476852ea4b9210 | |
parent | upgraded to libflate 0.1.21 (diff) | |
download | miniserve-17ef61a126e81c9ecfd1ebdd89537e854a06cae6.tar.gz miniserve-17ef61a126e81c9ecfd1ebdd89537e854a06cae6.zip |
Switched to standard Rust logging system
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | Cargo.toml | 3 | ||||
-rw-r--r-- | src/archive.rs | 7 | ||||
-rw-r--r-- | src/errors.rs | 15 | ||||
-rw-r--r-- | src/listing.rs | 16 | ||||
-rw-r--r-- | src/main.rs | 19 |
6 files changed, 22 insertions, 39 deletions
@@ -781,6 +781,7 @@ dependencies = [ "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "htmlescape 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "libflate 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "maud 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)", "nanoid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -41,4 +41,5 @@ tar = "0.4" bytes = "0.4.12" futures = "0.1.25" libflate = "0.1.21" -failure = "0.1.5"
\ No newline at end of file +failure = "0.1.5" +log = "0.4.6"
\ No newline at end of file diff --git a/src/archive.rs b/src/archive.rs index c535c50..e1460b9 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -6,7 +6,6 @@ use serde::Deserialize; use std::io; use std::path::PathBuf; use tar::Builder; -use yansi::Color; use crate::errors; @@ -100,7 +99,7 @@ fn tar(src_dir: String, inner_folder: String) -> Result<Vec<u8>, errors::Compres errors::CompressionErrorKind::TarBuildingError { message: format!( "failed to append the content of {} in the TAR archive", - color_path(&src_dir) + &src_dir ), }, )?; @@ -132,7 +131,3 @@ fn gzip(mut data: &[u8]) -> Result<Vec<u8>, errors::CompressionError> { Ok(data) } - -fn color_path(path: &str) -> String { - Color::White.paint(path).bold().to_string() -} diff --git a/src/errors.rs b/src/errors.rs index 8cfedff..a9b6c74 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,6 +1,5 @@ use failure::{Backtrace, Context, Fail}; use std::fmt::{self, Debug, Display}; -use yansi::{Color, Paint}; /// Kinds of errors which might happen during the generation of an archive #[derive(Debug, Fail)] @@ -22,18 +21,10 @@ pub enum CompressionErrorKind { /// Prints the full chain of error, up to the root cause. /// If RUST_BACKTRACE is set to 1, also prints the backtrace for each error pub fn print_error_chain(err: CompressionError) { - println!( - "{error} {err}", - error = Paint::red("error:").bold(), - err = Paint::white(&err).bold() - ); + log::error!("{}", &err); print_backtrace(&err); for cause in Fail::iter_causes(&err) { - println!( - "{} {}", - Color::RGB(255, 192, 0).paint("caused by:").to_string(), - cause - ); + log::error!("caused by: {}", cause); print_backtrace(cause); } } @@ -44,7 +35,7 @@ fn print_backtrace(err: &dyn Fail) { if let Some(backtrace) = err.backtrace() { let backtrace = backtrace.to_string(); if backtrace != "" { - println!("{}", backtrace); + log::error!("{}", backtrace); } } } diff --git a/src/listing.rs b/src/listing.rs index a9f0f19..b820aa4 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -7,7 +7,6 @@ use serde::Deserialize; use std::io; use std::path::Path; use std::time::SystemTime; -use yansi::Color; use crate::archive; use crate::errors; @@ -229,19 +228,14 @@ pub fn directory_listing<S>( } if let Some(compression_method) = &download { - println!( - "{info} Creating an archive ({extension}) of {path}...", - info = Color::Blue.paint("info:").bold(), - extension = Color::White.paint(compression_method.extension()).bold(), - path = Color::White.paint(&dir.path.display().to_string()).bold() + log::info!( + "Creating an archive ({extension}) of {path}...", + extension = compression_method.extension(), + path = &dir.path.display().to_string() ); match archive::create_archive_file(&compression_method, &dir.path) { Ok((filename, content)) => { - println!( - "{success} {file} successfully created !", - success = Color::Green.paint("success:").bold(), - file = Color::White.paint(&filename).bold(), - ); + log::info!("{file} successfully created !", file = &filename); Ok(HttpResponse::Ok() .content_type(compression_method.content_type()) .content_length(content.len() as u64) diff --git a/src/main.rs b/src/main.rs index 260551c..f662a73 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,6 +50,13 @@ fn main() { } let miniserve_config = args::parse_args(); + + let _ = if miniserve_config.verbose { + TermLogger::init(LevelFilter::Info, Config::default()) + } else { + TermLogger::init(LevelFilter::Error, Config::default()) + }; + if miniserve_config.no_symlinks && miniserve_config .path @@ -58,16 +65,10 @@ fn main() { .file_type() .is_symlink() { - println!( - "{error} The no-symlinks option cannot be used with a symlink path", - error = Paint::red("error:").bold(), - ); + log::error!("The no-symlinks option cannot be used with a symlink path"); return; } - if miniserve_config.verbose { - let _ = TermLogger::init(LevelFilter::Info, Config::default()); - } let sys = actix::System::new("miniserve"); let inside_config = miniserve_config.clone(); @@ -121,7 +122,7 @@ fn main() { version = crate_version!() ); if !miniserve_config.path_explicitly_chosen { - println!("{info} miniserve has been invoked without an explicit path so it will serve the current directory.", info=Color::Blue.paint("info:").bold()); + println!("{warning} miniserve has been invoked without an explicit path so it will serve the current directory.", warning=Color::RGB(255, 192, 0).paint("Notice:").bold()); println!( " Invoke with -h|--help to see options or invoke as `miniserve .` to hide this advice." ); @@ -166,7 +167,7 @@ fn main() { path = Color::Yellow.paint(path_string).bold(), addresses = addresses, ); - println!("Quit by pressing CTRL-C"); + println!("\nQuit by pressing CTRL-C"); let _ = sys.run(); } |