Improved logging to console (#440)
* Remove redundant timestamp. * Measure block processing in the logs * Use tabs to separate status. * Show updates every 1000 blocks. * Reword some warnings. * Add some color to log level. * Reduce code redundancy * No need to specify the type for blocks_speed * Utilize the return value of match. * Count all peers. * Add whitespaces * Remove another redundant timestamp * One item per line * Use tabs not spaces * Remove unused import * Remove redundant time imports * Paint it black.
This commit is contained in:
parent
a2ae59c0e3
commit
b2faa05ee7
|
@ -4,7 +4,7 @@ extern crate env_logger;
|
||||||
extern crate time;
|
extern crate time;
|
||||||
|
|
||||||
use ansi_term::Colour as Color;
|
use ansi_term::Colour as Color;
|
||||||
use log::LogRecord;
|
use log::{LogRecord, LogLevel};
|
||||||
use env_logger::LogBuilder;
|
use env_logger::LogBuilder;
|
||||||
|
|
||||||
fn strftime() -> String {
|
fn strftime() -> String {
|
||||||
|
@ -29,7 +29,18 @@ pub struct DateAndColorLogFormatter;
|
||||||
impl LogFormatter for DateAndColorLogFormatter {
|
impl LogFormatter for DateAndColorLogFormatter {
|
||||||
fn format(&self, record: &LogRecord) -> String {
|
fn format(&self, record: &LogRecord) -> String {
|
||||||
let timestamp = strftime();
|
let timestamp = strftime();
|
||||||
format!("{} {} {} {}", Color::Black.bold().paint(timestamp), record.level(), record.target(), record.args())
|
let log_level = match record.level() {
|
||||||
|
LogLevel::Error => Color::Fixed(9).bold().paint(record.level().to_string()),
|
||||||
|
LogLevel::Warn => Color::Fixed(11).bold().paint(record.level().to_string()),
|
||||||
|
LogLevel::Info => Color::Fixed(10).paint(record.level().to_string()),
|
||||||
|
LogLevel::Debug => Color::Fixed(14).paint(record.level().to_string()),
|
||||||
|
LogLevel::Trace => Color::Fixed(12).paint(record.level().to_string()),
|
||||||
|
};
|
||||||
|
format!("{} {} {} {}"
|
||||||
|
, Color::Fixed(8).bold().paint(timestamp)
|
||||||
|
, log_level
|
||||||
|
, Color::Fixed(8).paint(record.target())
|
||||||
|
, record.args())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ use std::collections::hash_map::Entry;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use time;
|
|
||||||
use time::precise_time_s;
|
use time::precise_time_s;
|
||||||
use chain::{IndexedBlockHeader, IndexedTransaction, Transaction, IndexedBlock};
|
use chain::{IndexedBlockHeader, IndexedTransaction, Transaction, IndexedBlock};
|
||||||
use message::types;
|
use message::types;
|
||||||
|
@ -826,17 +825,17 @@ impl<T> SynchronizationClientCore<T> where T: TaskExecutor {
|
||||||
/// Print synchronization information
|
/// Print synchronization information
|
||||||
pub fn print_synchronization_information(&mut self) {
|
pub fn print_synchronization_information(&mut self) {
|
||||||
if let State::Synchronizing(timestamp, num_of_blocks) = self.state {
|
if let State::Synchronizing(timestamp, num_of_blocks) = self.state {
|
||||||
let new_timestamp = time::precise_time_s();
|
let new_timestamp = precise_time_s();
|
||||||
let timestamp_diff = new_timestamp - timestamp;
|
let timestamp_diff = new_timestamp - timestamp;
|
||||||
let new_num_of_blocks = self.chain.best_storage_block().number;
|
let new_num_of_blocks = self.chain.best_storage_block().number;
|
||||||
let blocks_diff = if new_num_of_blocks > num_of_blocks { new_num_of_blocks - num_of_blocks } else { 0 };
|
let blocks_diff = if new_num_of_blocks > num_of_blocks { new_num_of_blocks - num_of_blocks } else { 0 };
|
||||||
if timestamp_diff >= 60.0 || blocks_diff > 1000 {
|
if timestamp_diff >= 60.0 || blocks_diff >= 1000 {
|
||||||
self.state = State::Synchronizing(time::precise_time_s(), new_num_of_blocks);
|
self.state = State::Synchronizing(precise_time_s(), new_num_of_blocks);
|
||||||
|
let blocks_speed = blocks_diff as f64 / timestamp_diff;
|
||||||
use time;
|
info!(target: "sync", "Processed {} blocks in {:.2} seconds ({:.2} blk/s).\tPeers: {:?}.\tChain: {:?}"
|
||||||
info!(target: "sync", "{:?} Processed {} blocks in {:.2} seconds. Peers: {:?}. Chain: {:?}"
|
, blocks_diff
|
||||||
, time::strftime("%H:%M:%S", &time::now()).unwrap()
|
, timestamp_diff
|
||||||
, blocks_diff, timestamp_diff
|
, blocks_speed
|
||||||
, self.peers_tasks.information()
|
, self.peers_tasks.information()
|
||||||
, self.chain.information());
|
, self.chain.information());
|
||||||
}
|
}
|
||||||
|
@ -987,7 +986,7 @@ impl<T> SynchronizationClientCore<T> where T: TaskExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.shared_state.update_synchronizing(true);
|
self.shared_state.update_synchronizing(true);
|
||||||
self.state = State::Synchronizing(time::precise_time_s(), self.chain.best_storage_block().number);
|
self.state = State::Synchronizing(precise_time_s(), self.chain.best_storage_block().number);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Switch to nearly saturated state
|
/// Switch to nearly saturated state
|
||||||
|
@ -1027,9 +1026,7 @@ impl<T> SynchronizationClientCore<T> where T: TaskExecutor {
|
||||||
self.chain.forget_all_blocks_with_state(BlockState::Requested);
|
self.chain.forget_all_blocks_with_state(BlockState::Requested);
|
||||||
self.chain.forget_all_blocks_with_state(BlockState::Scheduled);
|
self.chain.forget_all_blocks_with_state(BlockState::Scheduled);
|
||||||
|
|
||||||
use time;
|
info!(target: "sync", "Switched to saturated state.\tChain: {:?}",
|
||||||
info!(target: "sync", "{:?} @ Switched to saturated state. Chain information: {:?}",
|
|
||||||
time::strftime("%H:%M:%S", &time::now()).unwrap(),
|
|
||||||
self.chain.information());
|
self.chain.information());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -192,7 +192,7 @@ pub fn manage_synchronization_peers_blocks(config: &ManagePeersConfig, peers: Pe
|
||||||
}
|
}
|
||||||
|
|
||||||
// decrease score && move to the idle queue
|
// decrease score && move to the idle queue
|
||||||
warn!(target: "sync", "Failed to get requested block from peer#{} in {} seconds", worst_peer_index, time_diff);
|
warn!(target: "sync", "Failed to get requested block from peer#{} in {:.2} seconds.", worst_peer_index, time_diff);
|
||||||
let failed_blocks = peers_tasks.reset_blocks_tasks(worst_peer_index);
|
let failed_blocks = peers_tasks.reset_blocks_tasks(worst_peer_index);
|
||||||
|
|
||||||
// mark blocks as failed
|
// mark blocks as failed
|
||||||
|
@ -202,9 +202,9 @@ pub fn manage_synchronization_peers_blocks(config: &ManagePeersConfig, peers: Pe
|
||||||
|
|
||||||
// if peer failed many times => forget it
|
// if peer failed many times => forget it
|
||||||
if peers_tasks.on_peer_block_failure(worst_peer_index) {
|
if peers_tasks.on_peer_block_failure(worst_peer_index) {
|
||||||
warn!(target: "sync", "Too many failures for peer#{}. Excluding from synchronization", worst_peer_index);
|
warn!(target: "sync", "Too many failures for peer#{}. Excluding from synchronization.", worst_peer_index);
|
||||||
peers_tasks.unuseful_peer(worst_peer_index);
|
peers_tasks.unuseful_peer(worst_peer_index);
|
||||||
peers.misbehaving(worst_peer_index, &format!("Too many failures"));
|
peers.misbehaving(worst_peer_index, &format!("Too many failures."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,8 +232,8 @@ pub fn manage_synchronization_peers_headers(config: &ManagePeersConfig, peers: P
|
||||||
|
|
||||||
// if peer failed many times => forget it
|
// if peer failed many times => forget it
|
||||||
if peers_tasks.on_peer_headers_failure(worst_peer_index) {
|
if peers_tasks.on_peer_headers_failure(worst_peer_index) {
|
||||||
warn!(target: "sync", "Too many headers failures for peer#{}. Excluding from synchronization", worst_peer_index);
|
warn!(target: "sync", "Too many header failures for peer#{}. Excluding from synchronization.", worst_peer_index);
|
||||||
peers.misbehaving(worst_peer_index, &format!("Too many headers failures"));
|
peers.misbehaving(worst_peer_index, &format!("Too many header failures."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,14 +145,14 @@ impl PeersContainer for PeersImpl {
|
||||||
|
|
||||||
fn misbehaving(&self, peer_index: PeerIndex, reason: &str) {
|
fn misbehaving(&self, peer_index: PeerIndex, reason: &str) {
|
||||||
if let Some(peer) = self.peers.write().remove(&peer_index) {
|
if let Some(peer) = self.peers.write().remove(&peer_index) {
|
||||||
warn!(target: "sync", "Disconnecting from peer#{} due to misbehaving: {}", peer_index, reason);
|
warn!(target: "sync", "Disconnecting from peer#{} due to misbehavior: {}", peer_index, reason);
|
||||||
peer.connection.close();
|
peer.connection.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dos(&self, peer_index: PeerIndex, reason: &str) {
|
fn dos(&self, peer_index: PeerIndex, reason: &str) {
|
||||||
if let Some(peer) = self.peers.write().remove(&peer_index) {
|
if let Some(peer) = self.peers.write().remove(&peer_index) {
|
||||||
warn!(target: "sync", "Disconnecting from peer#{} due to DOS: {}", peer_index, reason);
|
warn!(target: "sync", "Disconnecting from peer#{} due to DoS: {}", peer_index, reason);
|
||||||
peer.connection.close();
|
peer.connection.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@ const BLOCKS_TO_INSPECT: usize = 32;
|
||||||
|
|
||||||
/// Information on synchronization peers
|
/// Information on synchronization peers
|
||||||
pub struct Information {
|
pub struct Information {
|
||||||
|
/// total # of peers.
|
||||||
|
pub all: usize,
|
||||||
/// # of peers that are marked as useful for current synchronization session && have no pending requests.
|
/// # of peers that are marked as useful for current synchronization session && have no pending requests.
|
||||||
pub idle: usize,
|
pub idle: usize,
|
||||||
/// # of peers that are marked as non-useful for current synchronization session && have no pending requests.
|
/// # of peers that are marked as non-useful for current synchronization session && have no pending requests.
|
||||||
|
@ -93,6 +95,7 @@ impl PeersTasks {
|
||||||
pub fn information(&self) -> Information {
|
pub fn information(&self) -> Information {
|
||||||
let active_for_headers: HashSet<_> = self.headers_requests.keys().cloned().collect();
|
let active_for_headers: HashSet<_> = self.headers_requests.keys().cloned().collect();
|
||||||
Information {
|
Information {
|
||||||
|
all: self.all.len(),
|
||||||
idle: self.idle_for_blocks.difference(&active_for_headers).count(),
|
idle: self.idle_for_blocks.difference(&active_for_headers).count(),
|
||||||
unuseful: self.unuseful.len(),
|
unuseful: self.unuseful.len(),
|
||||||
active: active_for_headers.union(&self.blocks_requests.keys().cloned().collect()).count(),
|
active: active_for_headers.union(&self.blocks_requests.keys().cloned().collect()).count(),
|
||||||
|
@ -375,7 +378,7 @@ impl PeerStats {
|
||||||
|
|
||||||
impl fmt::Debug for Information {
|
impl fmt::Debug for Information {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "[active:{}, idle:{}, bad:{}]", self.active, self.idle, self.unuseful)
|
write!(f, "{} (act: {}, idl: {}, bad: {})", self.all, self.active, self.idle, self.unuseful)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue