Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Commit

Permalink
Added env_logger
Browse files Browse the repository at this point in the history
Added in env_logger for better logging

Signed-off-by: Marko Baricevic <marbar3778@yahoo.com>
  • Loading branch information
tac0turtle committed May 22, 2019
1 parent 1cbb041 commit fee6aa0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Expand Up @@ -16,6 +16,8 @@ protobuf = "2.2.0"
byteorder = "1.2.7"
integer-encoding = "1.0.5"
mockstream = "0.0.3"
log = "0.4.6"
env_logger = "0.6.1"

[build-dependencies]
protobuf-codegen-pure = "2.2.0"
4 changes: 4 additions & 0 deletions src/lib.rs
Expand Up @@ -26,6 +26,10 @@ extern crate integer_encoding;
extern crate mockstream;
extern crate protobuf;

#[macro_use]
extern crate log;
extern crate env_logger;

mod messages;
mod server;
mod stream;
Expand Down
8 changes: 5 additions & 3 deletions src/server.rs
Expand Up @@ -5,6 +5,7 @@ use std::net::*;
use std::ops::DerefMut;
use std::sync::{Arc, Mutex};
use std::thread;
use env_logger::Env;

use messages::abci::*;
use stream::AbciStream;
Expand All @@ -14,6 +15,7 @@ pub fn serve<A>(app: A, addr: SocketAddr) -> io::Result<()>
where
A: Application + 'static + Send + Sync,
{
env_logger::from_env(Env::default().default_filter_or("info")).init();
let listener = TcpListener::bind(addr).unwrap();

// Wrap the app atomically and clone for each connection.
Expand All @@ -23,12 +25,12 @@ where
let app_instance = Arc::clone(&app);
match new_connection {
Ok(stream) => {
println!("Got connection! {:?}", stream);
info!("Got connection! {:?}", stream);
thread::spawn(move || handle_stream(AbciStream::from(stream), &app_instance));
}
Err(err) => {
// We need all 3 connections...
panic!("Connection failed: {}", err);
warn!("Connection failed: {}", err);
}
}
}
Expand All @@ -50,7 +52,7 @@ where
_ => break,
}
}
println!("Connection closed on {:?}", stream);
info!("Connection closed on {:?}", stream);
}

fn respond<A>(stream: &mut AbciStream, app: &mut A, request: &Request) -> io::Result<()>
Expand Down

0 comments on commit fee6aa0

Please sign in to comment.