"base64",
"chrono",
"clap",
+ "env_logger",
"futures",
"get_if_addrs",
"headers",
"hyper",
"lazy_static",
+ "log",
"md5",
"mime_guess",
"percent-encoding",
"uuid",
]
+[[package]]
+name = "env_logger"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3"
+dependencies = [
+ "humantime",
+ "log",
+]
+
[[package]]
name = "event-listener"
version = "2.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
+[[package]]
+name = "humantime"
+version = "2.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
+
[[package]]
name = "hyper"
version = "0.14.19"
mod auth;
mod server;
+#[macro_use]
+extern crate log;
+
pub type BoxResult<T> = Result<T, Box<dyn std::error::Error>>;
+use std::env;
+use std::io::Write;
+
use crate::args::{encode_uri, matches, Args};
use crate::server::serve;
}
async fn run() -> BoxResult<()> {
+ if env::var("RUST_LOG").is_err() {
+ env::set_var("RUST_LOG", "info")
+ }
+ env_logger::builder()
+ .format(|buf, record| {
+ let timestamp = buf.timestamp();
+ writeln!(buf, "[{} {}] {}", timestamp, record.level(), record.args())
+ })
+ .init();
+
let args = Args::parse(matches())?;
tokio::select! {
ret = serve(args) => {
use async_walkdir::WalkDir;
use async_zip::write::{EntryOptions, ZipFileWriter};
use async_zip::Compression;
-use chrono::{Local, TimeZone, Utc};
+use chrono::{TimeZone, Utc};
use futures::stream::StreamExt;
use futures::TryStreamExt;
use get_if_addrs::get_if_addrs;
let uri = req.uri().clone();
let cors = self.args.cors;
- let timestamp = Local::now().format("%d/%b/%Y %H:%M:%S");
let mut res = match self.handle(req).await {
Ok(res) => {
- println!(r#"[{}] "{} {}" - {}"#, timestamp, method, uri, res.status());
+ info!(r#""{} {}" - {}"#, method, uri, res.status());
res
}
Err(err) => {
let mut res = Response::default();
let status = StatusCode::INTERNAL_SERVER_ERROR;
status!(res, status);
- eprintln!(
- r#"[{}] "{} {}" - {} {}"#,
- timestamp, method, uri, status, err
- );
+ error!(r#""{} {}" - {} {}"#, method, uri, status, err);
res
}
};
let path = path.to_owned();
tokio::spawn(async move {
if let Err(e) = zip_dir(&mut writer, &path).await {
- eprintln!("Failed to zip {}, {}", path.display(), e);
+ error!("Failed to zip {}, {}", path.display(), e);
}
});
let stream = ReaderStream::new(reader);