Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/consistent logging #93

Merged
merged 5 commits into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions common/addressing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
log = "0.4"
pretty_env_logger = "0.3"
2 changes: 2 additions & 0 deletions common/clients/directory-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
log = "0.4"
pretty_env_logger = "0.3"
reqwest = "0.9.22"
serde = { version = "1.0.104", features = ["derive"] }

Expand Down
3 changes: 2 additions & 1 deletion common/clients/directory-client/src/presence.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::requests::presence_topology_get::PresenceTopologyGetRequester;
use crate::{Client, Config, DirectoryClient};
use log::*;
use serde::{Deserialize, Serialize};
use std::convert::TryInto;
use std::io;
Expand Down Expand Up @@ -159,7 +160,7 @@ pub struct Topology {

impl NymTopology for Topology {
fn new(directory_server: String) -> Self {
println!("Using directory server: {:?}", directory_server);
debug!("Using directory server: {:?}", directory_server);
let directory_config = Config {
base_url: directory_server,
};
Expand Down
1 change: 1 addition & 0 deletions common/clients/mix-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2018"

[dependencies]
log = "0.4.8"
pretty_env_logger = "0.3"
rand = "0.7.2"
rand_distr = "0.2.2"
tokio = { version = "0.2", features = ["full"] }
Expand Down
1 change: 1 addition & 0 deletions common/clients/provider-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition = "2018"
[dependencies]
futures = "0.3.1"
log = "0.4.8"
pretty_env_logger = "0.3"
tokio = { version = "0.2", features = ["full"] }

## internal
Expand Down
11 changes: 5 additions & 6 deletions common/clients/provider-client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use futures::io::Error;
use log::*;
use sfw_provider_requests::requests::{ProviderRequest, PullRequest, RegisterRequest};
use sfw_provider_requests::responses::{
ProviderResponse, ProviderResponseError, PullResponse, RegisterResponse,
Expand Down Expand Up @@ -67,16 +68,14 @@ impl ProviderClient {

socket.set_keepalive(Some(Duration::from_secs(2))).unwrap();
socket.write_all(&bytes[..]).await?;
if let Err(_e) = socket.shutdown(Shutdown::Write) {
// TODO: make it a silent log once we have a proper logging library
// eprintln!("failed to close write part of the socket; err = {:?}", e)
if let Err(e) = socket.shutdown(Shutdown::Write) {
warn!("failed to close write part of the socket; err = {:?}", e)
}

let mut response = Vec::new();
socket.read_to_end(&mut response).await?;
if let Err(_e) = socket.shutdown(Shutdown::Read) {
// TODO: make it a silent log once we have a proper logging library
// eprintln!("failed to close read part of the socket; err = {:?}", e)
if let Err(e) = socket.shutdown(Shutdown::Read) {
warn!("failed to close read part of the socket; err = {:?}", e)
}

Ok(response)
Expand Down
2 changes: 2 additions & 0 deletions common/clients/validator-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
log = "0.4"
pretty_env_logger = "0.3"
2 changes: 2 additions & 0 deletions common/crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ edition = "2018"
[dependencies]
base64 = "0.11.0"
curve25519-dalek = "1.2.3"
log = "0.4"
pretty_env_logger = "0.3"
rand = "0.7.2"
rand_os = "0.1"
1 change: 1 addition & 0 deletions common/healthcheck/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ edition = "2018"
futures = "0.3.1"
itertools = "0.8.2"
log = "0.4.8"
pretty_env_logger = "0.3"
serde = "1.0.104"
serde_derive = "1.0.104"
tokio = { version = "0.2", features = ["full"] }
Expand Down
2 changes: 2 additions & 0 deletions common/pemstore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
log = "0.4"
pem = "0.7.0"
pretty_env_logger = "0.3"

## internal
crypto = {path = "../crypto"}
3 changes: 2 additions & 1 deletion common/topology/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ edition = "2018"
base64 = "0.11.0"
curve25519-dalek = "1.2.3"
itertools = "0.8.2"
log = "0.4.8"
log = "0.4"
pretty_env_logger = "0.3"
rand = "0.7.2"
serde = { version = "1.0.104", features = ["derive"] }

Expand Down
4 changes: 3 additions & 1 deletion mixnode/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ edition = "2018"
base64 = "0.11.0"
clap = "2.33.0"
curve25519-dalek = "1.2.3"
dotenv = "0.15.0"
futures = "0.3.1"
log = "0.4.8"
log = "0.4"
pretty_env_logger = "0.3"
tokio = { version = "0.2", features = ["full"] }

## internal
Expand Down
6 changes: 5 additions & 1 deletion mixnode/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use clap::{App, Arg, ArgMatches, SubCommand};
use log::*;
use std::process;

mod mix_peer;
mod node;

fn main() {
dotenv::dotenv().ok();
pretty_env_logger::init();

let arg_matches = App::new("Nym Mixnode")
.version(built_info::PKG_VERSION)
.author("Nymtech")
Expand Down Expand Up @@ -54,7 +58,7 @@ fn main() {
.get_matches();

if let Err(e) = execute(arg_matches) {
println!("{}", e);
error!("{}", e);
process::exit(1);
}
}
Expand Down
11 changes: 6 additions & 5 deletions mixnode/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use curve25519_dalek::scalar::Scalar;
use futures::channel::mpsc;
use futures::lock::Mutex;
use futures::SinkExt;
use log::*;
use sphinx::header::delays::Delay as SphinxDelay;
use sphinx::{ProcessedPacket, SphinxPacket};
use std::net::SocketAddr;
Expand Down Expand Up @@ -140,15 +141,15 @@ impl PacketProcessor {
.await
.unwrap();

println!("RECIPIENT: {:?}", forwarding_data.recipient);
trace!("RECIPIENT: {:?}", forwarding_data.recipient);
match forwarding_data
.recipient
.send(forwarding_data.packet.to_bytes())
.await
{
Ok(()) => (),
Err(e) => {
println!(
warn!(
"failed to write bytes to next mix peer. err = {:?}",
e.to_string()
);
Expand Down Expand Up @@ -190,7 +191,7 @@ impl MixNode {
match socket.read(&mut buf).await {
// socket closed
Ok(n) if n == 0 => {
println!("Remote connection closed.");
trace!("Remote connection closed.");
return;
}
Ok(_) => {
Expand All @@ -203,14 +204,14 @@ impl MixNode {
PacketProcessor::wait_and_forward(fwd_data).await;
}
Err(e) => {
println!("failed to read from socket; err = {:?}", e);
warn!("failed to read from socket; err = {:?}", e);
return;
}
};

// Write the some data back
if let Err(e) = socket.write_all(b"foomp").await {
println!("failed to write reply to socket; err = {:?}", e);
warn!("failed to write reply to socket; err = {:?}", e);
return;
}
}
Expand Down
5 changes: 3 additions & 2 deletions nym-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ base64 = "0.11.0"
clap = "2.33.0"
curve25519-dalek = "1.2.3"
dirs = "2.0.2"
env_logger = "0.7.1"
dotenv = "0.15.0"
futures = "0.3.1"
hex = "0.4.0"
log = "0.4.8"
log = "0.4"
pem = "0.7.0"
pretty_env_logger = "0.3"
reqwest = "0.9.22"
serde = { version = "1.0.104", features = ["derive"] }
serde_json = "1.0.44"
Expand Down
2 changes: 1 addition & 1 deletion nym-client/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ impl NymClient {
});

// this line in theory should never be reached as the runtime should be permanently blocked on traffic senders
eprintln!("The client went kaput...");
error!("The client went kaput...");
Ok(())
}
}
3 changes: 2 additions & 1 deletion nym-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ pub mod config;
mod sockets;

fn main() {
env_logger::init();
dotenv::dotenv().ok();
pretty_env_logger::init();

let arg_matches = App::new("Nym Client")
.version(built_info::PKG_VERSION)
Expand Down
Loading