Use log and beautylog

This commit is contained in:
Thomas Forgione 2019-02-27 11:09:38 +01:00
parent 201fce5088
commit 3f8cdc4aee
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
3 changed files with 14 additions and 14 deletions

View File

@ -10,6 +10,8 @@ notify-rust = "3.4.2"
colored = "1.6.1" colored = "1.6.1"
percent-encoding = "1.0.1" percent-encoding = "1.0.1"
hyper = "0.12.10" hyper = "0.12.10"
log = "0.4.6"
beautylog = "0.1.0"
[[bin]] [[bin]]
name = "mars-server" name = "mars-server"

View File

@ -1,13 +1,9 @@
extern crate colored; #[macro_use]
extern crate percent_encoding; extern crate log;
extern crate hyper;
extern crate mars;
use std::env; use std::env;
use std::process::exit; use std::process::exit;
use colored::*;
use percent_encoding::{percent_decode, percent_encode, DEFAULT_ENCODE_SET}; use percent_encoding::{percent_decode, percent_encode, DEFAULT_ENCODE_SET};
use hyper::Client; use hyper::Client;
@ -17,9 +13,11 @@ use mars::{GeneralBuilder, builder_arguments_from_string};
fn main() { fn main() {
beautylog::init(log::LevelFilter::Info).ok();
let current_dir = match env::current_dir() { let current_dir = match env::current_dir() {
Err(e) => { Err(e) => {
eprintln!("Couldn't find current directory: {:?}", e); error!("couldn't find current directory: {}", e);
exit(1); exit(1);
}, },
Ok(path) => { Ok(path) => {
@ -48,7 +46,7 @@ fn fetch_url(uri: hyper::Uri) -> impl Future<Item=(), Error=()> {
.map(|_| ()) .map(|_| ())
// If there was an error, build in client // If there was an error, build in client
.map_err(move |_| { .map_err(move |_| {
eprintln!("{}", "Server not listening, building in client...".bold().yellow()); warn!("{}", "server not listening, building in client...");
let builder = GeneralBuilder::new(); let builder = GeneralBuilder::new();
let uri = percent_decode(uri.path().as_bytes()).decode_utf8().unwrap(); let uri = percent_decode(uri.path().as_bytes()).decode_utf8().unwrap();
let (path, args) = builder_arguments_from_string(&*uri); let (path, args) = builder_arguments_from_string(&*uri);

View File

@ -1,7 +1,5 @@
extern crate colored; #[macro_use]
extern crate percent_encoding; extern crate log;
extern crate hyper;
extern crate mars;
use std::thread; use std::thread;
use std::sync::{Mutex, Arc, mpsc}; use std::sync::{Mutex, Arc, mpsc};
@ -18,6 +16,8 @@ use mars::{GeneralBuilder, builder_arguments_from_string};
fn main() { fn main() {
beautylog::init(log::LevelFilter::Info).ok();
let (tx, rx) = mpsc::channel(); let (tx, rx) = mpsc::channel();
let tasks = Arc::new(Mutex::new(vec![])); let tasks = Arc::new(Mutex::new(vec![]));
@ -38,9 +38,9 @@ fn main() {
}); });
r r
}) })
.map_err(|e| eprintln!("server error: {}", e)); .map_err(|e| error!("server error: {}", e));
println!("{}", format!("Mars server listening on {}...", addr).bold().green()); info!("mars server listening on {}...", addr);
hyper::rt::run(server); hyper::rt::run(server);
}); });