Replace logging backend to log4rs and add log rotation (#1789)
* Replace logging backend to flexi-logger and add log rotation * Changed flexi_logger to log4rs * Disable logging level filtering in Root logger * Support different logging levels for file and stdout * Don't log messages from modules other than Grin-related * Fix formatting * Place backed up compressed log copies into log file directory * Increase default log file size to 16 MiB * Add comment to config file on log_max_size option
This commit is contained in:
@@ -22,7 +22,6 @@ use common::types::{SyncState, SyncStatus};
|
||||
use core::core::hash::{Hash, Hashed, ZERO_HASH};
|
||||
use core::global;
|
||||
use p2p;
|
||||
use util::LOGGER;
|
||||
|
||||
pub struct BodySync {
|
||||
chain: Arc<chain::Chain>,
|
||||
@@ -94,7 +93,6 @@ impl BodySync {
|
||||
self.reset();
|
||||
|
||||
debug!(
|
||||
LOGGER,
|
||||
"body_sync: body_head - {}, {}, header_head - {}, {}, sync_head - {}, {}",
|
||||
body_head.last_block_h,
|
||||
body_head.height,
|
||||
@@ -148,7 +146,6 @@ impl BodySync {
|
||||
|
||||
if hashes_to_get.len() > 0 {
|
||||
debug!(
|
||||
LOGGER,
|
||||
"block_sync: {}/{} requesting blocks {:?} from {} peers",
|
||||
body_head.height,
|
||||
header_head.height,
|
||||
@@ -161,7 +158,7 @@ impl BodySync {
|
||||
for hash in hashes_to_get.clone() {
|
||||
if let Some(peer) = peers_iter.next() {
|
||||
if let Err(e) = peer.send_block_request(*hash) {
|
||||
debug!(LOGGER, "Skipped request to {}: {:?}", peer.info.addr, e);
|
||||
debug!("Skipped request to {}: {:?}", peer.info.addr, e);
|
||||
} else {
|
||||
self.body_sync_hashes.push(hash.clone());
|
||||
}
|
||||
@@ -199,7 +196,6 @@ impl BodySync {
|
||||
.filter(|x| !self.chain.get_block(*x).is_ok() && !self.chain.is_orphan(*x))
|
||||
.collect::<Vec<_>>();
|
||||
debug!(
|
||||
LOGGER,
|
||||
"body_sync: {}/{} blocks received, and no more in 200ms",
|
||||
self.body_sync_hashes.len() - hashes_not_get.len(),
|
||||
self.body_sync_hashes.len(),
|
||||
@@ -210,7 +206,6 @@ impl BodySync {
|
||||
None => {
|
||||
if Utc::now() - self.sync_start_ts > Duration::seconds(5) {
|
||||
debug!(
|
||||
LOGGER,
|
||||
"body_sync: 0/{} blocks received in 5s",
|
||||
self.body_sync_hashes.len(),
|
||||
);
|
||||
|
||||
@@ -20,7 +20,6 @@ use chain;
|
||||
use common::types::{Error, SyncState, SyncStatus};
|
||||
use core::core::hash::{Hash, Hashed};
|
||||
use p2p::{self, Peer};
|
||||
use util::LOGGER;
|
||||
|
||||
pub struct HeaderSync {
|
||||
sync_state: Arc<SyncState>,
|
||||
@@ -60,7 +59,6 @@ impl HeaderSync {
|
||||
// but ONLY on initial transition to HeaderSync state.
|
||||
let sync_head = self.chain.get_sync_head().unwrap();
|
||||
debug!(
|
||||
LOGGER,
|
||||
"sync: initial transition to HeaderSync. sync_head: {} at {}, reset to: {} at {}",
|
||||
sync_head.hash(),
|
||||
sync_head.height,
|
||||
@@ -141,8 +139,8 @@ impl HeaderSync {
|
||||
fn request_headers(&mut self, peer: &Peer) {
|
||||
if let Ok(locator) = self.get_locator() {
|
||||
debug!(
|
||||
LOGGER,
|
||||
"sync: request_headers: asking {} for headers, {:?}", peer.info.addr, locator,
|
||||
"sync: request_headers: asking {} for headers, {:?}",
|
||||
peer.info.addr, locator,
|
||||
);
|
||||
|
||||
let _ = peer.send_header_request(locator);
|
||||
@@ -165,7 +163,7 @@ impl HeaderSync {
|
||||
self.history_locators.clear();
|
||||
}
|
||||
|
||||
debug!(LOGGER, "sync: locator heights : {:?}", heights);
|
||||
debug!("sync: locator heights : {:?}", heights);
|
||||
|
||||
let mut locator: Vec<Hash> = vec![];
|
||||
let mut current = self.chain.get_block_header(&tip.last_block_h);
|
||||
@@ -237,7 +235,7 @@ impl HeaderSync {
|
||||
}
|
||||
}
|
||||
|
||||
debug!(LOGGER, "sync: locator heights': {:?}", new_heights);
|
||||
debug!("sync: locator heights': {:?}", new_heights);
|
||||
|
||||
// shrink history_locators properly
|
||||
if heights.len() > 1 {
|
||||
@@ -258,14 +256,13 @@ impl HeaderSync {
|
||||
}
|
||||
}
|
||||
debug!(
|
||||
LOGGER,
|
||||
"sync: history locators: len={}, shrunk={}",
|
||||
self.history_locators.len(),
|
||||
shrunk_size
|
||||
);
|
||||
}
|
||||
|
||||
debug!(LOGGER, "sync: locator: {:?}", locator);
|
||||
debug!("sync: locator: {:?}", locator);
|
||||
|
||||
Ok(locator)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ use common::types::{Error, SyncState, SyncStatus};
|
||||
use core::core::hash::Hashed;
|
||||
use core::global;
|
||||
use p2p::{self, Peer};
|
||||
use util::LOGGER;
|
||||
|
||||
/// Fast sync has 3 "states":
|
||||
/// * syncing headers
|
||||
@@ -77,10 +76,7 @@ impl StateSync {
|
||||
{
|
||||
let clone = self.sync_state.sync_error();
|
||||
if let Some(ref sync_error) = *clone.read() {
|
||||
error!(
|
||||
LOGGER,
|
||||
"fast_sync: error = {:?}. restart fast sync", sync_error
|
||||
);
|
||||
error!("fast_sync: error = {:?}. restart fast sync", sync_error);
|
||||
sync_need_restart = true;
|
||||
}
|
||||
drop(clone);
|
||||
@@ -92,8 +88,8 @@ impl StateSync {
|
||||
if !peer.is_connected() {
|
||||
sync_need_restart = true;
|
||||
info!(
|
||||
LOGGER,
|
||||
"fast_sync: peer connection lost: {:?}. restart", peer.info.addr,
|
||||
"fast_sync: peer connection lost: {:?}. restart",
|
||||
peer.info.addr,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -110,10 +106,7 @@ impl StateSync {
|
||||
|
||||
if let SyncStatus::TxHashsetDownload { .. } = self.sync_state.status() {
|
||||
if download_timeout {
|
||||
error!(
|
||||
LOGGER,
|
||||
"fast_sync: TxHashsetDownload status timeout in 10 minutes!"
|
||||
);
|
||||
error!("fast_sync: TxHashsetDownload status timeout in 10 minutes!");
|
||||
self.sync_state
|
||||
.set_sync_error(Error::P2P(p2p::Error::Timeout));
|
||||
}
|
||||
@@ -168,7 +161,6 @@ impl StateSync {
|
||||
}
|
||||
let bhash = txhashset_head.hash();
|
||||
debug!(
|
||||
LOGGER,
|
||||
"fast_sync: before txhashset request, header head: {} / {}, txhashset_head: {} / {}",
|
||||
header_head.height,
|
||||
header_head.last_block_h,
|
||||
@@ -176,7 +168,7 @@ impl StateSync {
|
||||
bhash
|
||||
);
|
||||
if let Err(e) = peer.send_txhashset_request(txhashset_head.height, bhash) {
|
||||
error!(LOGGER, "fast_sync: send_txhashset_request err! {:?}", e);
|
||||
error!("fast_sync: send_txhashset_request err! {:?}", e);
|
||||
return Err(e);
|
||||
}
|
||||
return Ok(peer.clone());
|
||||
|
||||
@@ -24,7 +24,6 @@ use grin::sync::body_sync::BodySync;
|
||||
use grin::sync::header_sync::HeaderSync;
|
||||
use grin::sync::state_sync::StateSync;
|
||||
use p2p::{self, Peers};
|
||||
use util::LOGGER;
|
||||
|
||||
pub fn run_sync(
|
||||
sync_state: Arc<SyncState>,
|
||||
@@ -164,7 +163,6 @@ fn needs_syncing(
|
||||
if peer.info.total_difficulty() <= local_diff {
|
||||
let ch = chain.head().unwrap();
|
||||
info!(
|
||||
LOGGER,
|
||||
"synchronized at {} @ {} [{}]",
|
||||
local_diff.to_num(),
|
||||
ch.height,
|
||||
@@ -175,7 +173,7 @@ fn needs_syncing(
|
||||
return (false, most_work_height);
|
||||
}
|
||||
} else {
|
||||
warn!(LOGGER, "sync: no peers available, disabling sync");
|
||||
warn!("sync: no peers available, disabling sync");
|
||||
return (false, 0);
|
||||
}
|
||||
} else {
|
||||
@@ -192,7 +190,6 @@ fn needs_syncing(
|
||||
let peer_diff = peer.info.total_difficulty();
|
||||
if peer_diff > local_diff.clone() + threshold.clone() {
|
||||
info!(
|
||||
LOGGER,
|
||||
"sync: total_difficulty {}, peer_difficulty {}, threshold {} (last 5 blocks), enabling sync",
|
||||
local_diff,
|
||||
peer_diff,
|
||||
|
||||
Reference in New Issue
Block a user