aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorboasting-squirrel <boasting.squirrel@gmail.com>2019-03-13 18:30:54 +0000
committerboasting-squirrel <boasting.squirrel@gmail.com>2019-03-13 18:30:54 +0000
commit17ef61a126e81c9ecfd1ebdd89537e854a06cae6 (patch)
tree24669a4d54650bd6b114012d3b476852ea4b9210
parentupgraded to libflate 0.1.21 (diff)
downloadminiserve-17ef61a126e81c9ecfd1ebdd89537e854a06cae6.tar.gz
miniserve-17ef61a126e81c9ecfd1ebdd89537e854a06cae6.zip
Switched to standard Rust logging system
-rw-r--r--Cargo.lock1
-rw-r--r--Cargo.toml3
-rw-r--r--src/archive.rs7
-rw-r--r--src/errors.rs15
-rw-r--r--src/listing.rs16
-rw-r--r--src/main.rs19
6 files changed, 22 insertions, 39 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 410cb9b..ff7dbc3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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)",
diff --git a/Cargo.toml b/Cargo.toml
index 922e1ca..e9cce56 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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();
}