Logs session end with total bytes transfered
This commit is contained in:
@@ -30,26 +30,28 @@ fn log_request(
|
||||
handshake_time: Option<u128>,
|
||||
) {
|
||||
let hs = handshake_time.map_or("failed".to_string(), |hs| format!("{}ms", hs));
|
||||
if !*crate::option::LOG_NO_COLOR {
|
||||
let (network, outbound_tag) = if !*crate::option::LOG_NO_COLOR {
|
||||
use colored::Colorize;
|
||||
let network_color = match sess.network {
|
||||
Network::Tcp => colored::Color::Blue,
|
||||
Network::Udp => colored::Color::Yellow,
|
||||
};
|
||||
info!(
|
||||
"[{}] [{}] [{}] [{}] {}",
|
||||
&sess.inbound_tag,
|
||||
sess.network.to_string().color(network_color),
|
||||
outbound_tag.color(*outbound_tag_color),
|
||||
hs,
|
||||
&sess.destination,
|
||||
);
|
||||
(
|
||||
sess.network.to_string().color(network_color).to_string(),
|
||||
outbound_tag.color(*outbound_tag_color).to_string(),
|
||||
)
|
||||
} else {
|
||||
info!(
|
||||
"[{}] [{}] [{}] [{}] {}",
|
||||
sess.network, &sess.inbound_tag, outbound_tag, hs, &sess.destination,
|
||||
);
|
||||
}
|
||||
(sess.network.to_string(), outbound_tag.to_string())
|
||||
};
|
||||
info!(
|
||||
"[{}] [{}] [{}] [{}] [{}] [{}]",
|
||||
sess.forwarded_source.unwrap_or_else(|| sess.source.ip()),
|
||||
network,
|
||||
&sess.inbound_tag,
|
||||
outbound_tag,
|
||||
hs,
|
||||
&sess.destination,
|
||||
);
|
||||
}
|
||||
|
||||
pub struct Dispatcher {
|
||||
|
||||
@@ -163,6 +163,22 @@ impl Counter {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn log_session_end(c: &Counter) {
|
||||
log::info!(
|
||||
"[{}] [{}] [{}] [{}] [{}] [{}] [{}] [END]",
|
||||
c.sess
|
||||
.forwarded_source
|
||||
.unwrap_or_else(|| c.sess.source.ip()),
|
||||
c.sess.network,
|
||||
c.sess.inbound_tag,
|
||||
c.sess.outbound_tag,
|
||||
c.sess.destination,
|
||||
c.bytes_sent(),
|
||||
c.bytes_recvd(),
|
||||
);
|
||||
}
|
||||
|
||||
pub struct StatManager {
|
||||
pub counters: Vec<Counter>,
|
||||
}
|
||||
@@ -182,7 +198,8 @@ impl StatManager {
|
||||
let mut i = 0;
|
||||
while i < sm.counters.len() {
|
||||
if sm.counters[i].recv_completed() && sm.counters[i].send_completed() {
|
||||
sm.counters.swap_remove(i);
|
||||
let c = sm.counters.swap_remove(i);
|
||||
log_session_end(&c);
|
||||
} else {
|
||||
i += 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user