added option to supress Transfer logging
Some checks are pending
continuous-integration/drone/push Build is running
Some checks are pending
continuous-integration/drone/push Build is running
This commit is contained in:
parent
b8d14bee77
commit
60dac9ea17
@ -1,5 +1,6 @@
|
||||
use crate::Peer;
|
||||
use number_prefix::{NumberPrefix, Prefixed, Standalone};
|
||||
use std::env;
|
||||
use std::net::SocketAddr;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
@ -33,7 +34,18 @@ impl EventListener for Vec<Box<EventListener>> {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LogListener;
|
||||
pub struct LogListener {
|
||||
log_transfer: bool,
|
||||
}
|
||||
|
||||
impl Default for LogListener {
|
||||
fn default() -> LogListener {
|
||||
let log = env::var("WG_LOG_TRANSFER")
|
||||
.map(|t| t.parse::<bool>().unwrap_or(true))
|
||||
.unwrap_or(false);
|
||||
LogListener { log_transfer: log }
|
||||
}
|
||||
}
|
||||
|
||||
impl EventListener for LogListener {
|
||||
fn name(&self) -> &'static str {
|
||||
@ -52,7 +64,7 @@ impl EventListener for LogListener {
|
||||
previous_addr,
|
||||
peer.endpoint.unwrap()
|
||||
),
|
||||
Event::Transfered { peer, tx, rx } => {
|
||||
Event::Transfered { peer, tx, rx } if self.log_transfer => {
|
||||
let prefix = |cnt: u64| match NumberPrefix::binary(cnt as f64) {
|
||||
Standalone(bytes) => format!("{}B", bytes),
|
||||
Prefixed(prefix, n) => format!("{:.0} {}B", n, prefix),
|
||||
@ -64,7 +76,7 @@ impl EventListener for LogListener {
|
||||
prefix(rx)
|
||||
);
|
||||
}
|
||||
|
||||
Event::Transfered { peer, tx, rx } => (),
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ fn listeners(opts: &Opts) -> Vec<Box<EventListener>> {
|
||||
listeners.push(Box::new(ScriptListener::new(events)))
|
||||
}
|
||||
if opts.log {
|
||||
listeners.push(Box::new(LogListener));
|
||||
listeners.push(Box::new(LogListener::default()));
|
||||
}
|
||||
println!("Enabled handlers: {}", (&listeners.iter().map(|l| l.name()).collect::<Vec<_>>()).join(", "));
|
||||
listeners
|
||||
|
Loading…
x
Reference in New Issue
Block a user