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:
eupn
2018-10-21 23:30:56 +03:00
committed by Ignotus Peverell
parent 0852b0c4cf
commit 1195071f5b
83 changed files with 582 additions and 897 deletions
+33 -64
View File
@@ -35,7 +35,7 @@ use p2p;
use pool;
use rand::prelude::*;
use store;
use util::{OneTime, LOGGER};
use util::OneTime;
/// Implementation of the NetAdapter for the . Gets notified when new
/// blocks and transactions are received and forwards to the chain and pool
@@ -74,7 +74,6 @@ impl p2p::ChainAdapter for NetToChainAdapter {
let header = self.chain().head_header().unwrap();
debug!(
LOGGER,
"Received tx {}, inputs: {}, outputs: {}, kernels: {}, going to process.",
tx_hash,
tx.inputs().len(),
@@ -88,13 +87,12 @@ impl p2p::ChainAdapter for NetToChainAdapter {
};
if let Err(e) = res {
debug!(LOGGER, "Transaction {} rejected: {:?}", tx_hash, e);
debug!("Transaction {} rejected: {:?}", tx_hash, e);
}
}
fn block_received(&self, b: core::Block, addr: SocketAddr) -> bool {
debug!(
LOGGER,
"Received block {} at {} from {}, inputs: {}, outputs: {}, kernels: {}, going to process.",
b.hash(),
b.header.height,
@@ -109,7 +107,6 @@ impl p2p::ChainAdapter for NetToChainAdapter {
fn compact_block_received(&self, cb: core::CompactBlock, addr: SocketAddr) -> bool {
let bhash = cb.hash();
debug!(
LOGGER,
"Received compact_block {} at {} from {}, outputs: {}, kernels: {}, kern_ids: {}, going to process.",
bhash,
cb.header.height,
@@ -125,7 +122,7 @@ impl p2p::ChainAdapter for NetToChainAdapter {
match core::Block::hydrate_from(cb, vec![]) {
Ok(block) => self.process_block(block, addr),
Err(e) => {
debug!(LOGGER, "Invalid hydrated block {}: {}", cb_hash, e);
debug!("Invalid hydrated block {}: {}", cb_hash, e);
return false;
}
}
@@ -135,7 +132,7 @@ impl p2p::ChainAdapter for NetToChainAdapter {
.chain()
.process_block_header(&cb.header, self.chain_opts())
{
debug!(LOGGER, "Invalid compact block header {}: {}", cb_hash, e);
debug!("Invalid compact block header {}: {}", cb_hash, e);
return !e.is_bad_data();
}
@@ -145,7 +142,6 @@ impl p2p::ChainAdapter for NetToChainAdapter {
};
debug!(
LOGGER,
"adapter: txs from tx pool - {}, (unknown kern_ids: {})",
txs.len(),
missing_short_ids.len(),
@@ -159,7 +155,7 @@ impl p2p::ChainAdapter for NetToChainAdapter {
let block = match core::Block::hydrate_from(cb.clone(), txs) {
Ok(block) => block,
Err(e) => {
debug!(LOGGER, "Invalid hydrated block {}: {}", cb.hash(), e);
debug!("Invalid hydrated block {}: {}", cb.hash(), e);
return false;
}
};
@@ -169,29 +165,22 @@ impl p2p::ChainAdapter for NetToChainAdapter {
.validate(&prev.total_kernel_offset, self.verifier_cache.clone())
.is_ok()
{
debug!(LOGGER, "adapter: successfully hydrated block from tx pool!");
debug!("adapter: successfully hydrated block from tx pool!");
self.process_block(block, addr)
} else {
if self.sync_state.status() == SyncStatus::NoSync {
debug!(
LOGGER,
"adapter: block invalid after hydration, requesting full block"
);
debug!("adapter: block invalid after hydration, requesting full block");
self.request_block(&cb.header, &addr);
true
} else {
debug!(
LOGGER,
"adapter: block invalid after hydration, ignoring it, cause still syncing"
);
true
}
}
} else {
debug!(
LOGGER,
"adapter: failed to retrieve previous block header (still syncing?)"
);
debug!("adapter: failed to retrieve previous block header (still syncing?)");
true
}
}
@@ -200,8 +189,8 @@ impl p2p::ChainAdapter for NetToChainAdapter {
fn header_received(&self, bh: core::BlockHeader, addr: SocketAddr) -> bool {
let bhash = bh.hash();
debug!(
LOGGER,
"Received block header {} at {} from {}, going to process.", bhash, bh.height, addr,
"Received block header {} at {} from {}, going to process.",
bhash, bh.height, addr,
);
// pushing the new block header through the header chain pipeline
@@ -209,16 +198,11 @@ impl p2p::ChainAdapter for NetToChainAdapter {
let res = self.chain().process_block_header(&bh, self.chain_opts());
if let &Err(ref e) = &res {
debug!(
LOGGER,
"Block header {} refused by chain: {:?}",
bhash,
e.kind()
);
debug!("Block header {} refused by chain: {:?}", bhash, e.kind());
if e.is_bad_data() {
debug!(
LOGGER,
"header_received: {} is a bad header, resetting header head", bhash
"header_received: {} is a bad header, resetting header head",
bhash
);
let _ = self.chain().reset_head();
return false;
@@ -239,7 +223,6 @@ impl p2p::ChainAdapter for NetToChainAdapter {
fn headers_received(&self, bhs: Vec<core::BlockHeader>, addr: SocketAddr) -> bool {
info!(
LOGGER,
"Received block headers {:?} from {}",
bhs.iter().map(|x| x.hash()).collect::<Vec<_>>(),
addr,
@@ -252,7 +235,7 @@ impl p2p::ChainAdapter for NetToChainAdapter {
// try to add headers to our header chain
let res = self.chain().sync_block_headers(&bhs, self.chain_opts());
if let &Err(ref e) = &res {
debug!(LOGGER, "Block headers refused by chain: {:?}", e);
debug!("Block headers refused by chain: {:?}", e);
if e.is_bad_data() {
return false;
@@ -262,14 +245,14 @@ impl p2p::ChainAdapter for NetToChainAdapter {
}
fn locate_headers(&self, locator: Vec<Hash>) -> Vec<core::BlockHeader> {
debug!(LOGGER, "locate_headers: {:?}", locator,);
debug!("locate_headers: {:?}", locator,);
let header = match self.find_common_header(locator) {
Some(header) => header,
None => return vec![],
};
debug!(LOGGER, "locate_headers: common header: {:?}", header.hash(),);
debug!("locate_headers: common header: {:?}", header.hash(),);
// looks like we know one, getting as many following headers as allowed
let hh = header.height;
@@ -281,18 +264,14 @@ impl p2p::ChainAdapter for NetToChainAdapter {
Err(e) => match e.kind() {
chain::ErrorKind::StoreErr(store::Error::NotFoundErr(_), _) => break,
_ => {
error!(LOGGER, "Could not build header locator: {:?}", e);
error!("Could not build header locator: {:?}", e);
return vec![];
}
},
}
}
debug!(
LOGGER,
"locate_headers: returning headers: {}",
headers.len(),
);
debug!("locate_headers: returning headers: {}", headers.len(),);
headers
}
@@ -317,10 +296,7 @@ impl p2p::ChainAdapter for NetToChainAdapter {
reader: read,
}),
Err(e) => {
warn!(
LOGGER,
"Couldn't produce txhashset data for block {}: {:?}", h, e
);
warn!("Couldn't produce txhashset data for block {}: {:?}", h, e);
None
}
}
@@ -367,12 +343,12 @@ impl p2p::ChainAdapter for NetToChainAdapter {
.chain()
.txhashset_write(h, txhashset_data, self.sync_state.as_ref())
{
error!(LOGGER, "Failed to save txhashset archive: {}", e);
error!("Failed to save txhashset archive: {}", e);
let is_good_data = !e.is_bad_data();
self.sync_state.set_sync_error(types::Error::Chain(e));
is_good_data
} else {
info!(LOGGER, "Received valid txhashset data for {}.", h);
info!("Received valid txhashset data for {}.", h);
true
}
}
@@ -447,7 +423,7 @@ impl NetToChainAdapter {
self.find_common_header(locator[1..].to_vec())
}
_ => {
error!(LOGGER, "Could not build header locator: {:?}", e);
error!("Could not build header locator: {:?}", e);
None
}
},
@@ -479,8 +455,8 @@ impl NetToChainAdapter {
}
Err(ref e) if e.is_bad_data() => {
debug!(
LOGGER,
"adapter: process_block: {} is a bad block, resetting head", bhash
"adapter: process_block: {} is a bad block, resetting head",
bhash
);
let _ = self.chain().reset_head();
@@ -495,14 +471,13 @@ impl NetToChainAdapter {
chain::ErrorKind::Orphan => {
// make sure we did not miss the parent block
if !self.chain().is_orphan(&prev_hash) && !self.sync_state.is_syncing() {
debug!(LOGGER, "adapter: process_block: received an orphan block, checking the parent: {:}", prev_hash);
debug!("adapter: process_block: received an orphan block, checking the parent: {:}", prev_hash);
self.request_block_by_hash(prev_hash, &addr)
}
true
}
_ => {
debug!(
LOGGER,
"adapter: process_block: block {} refused by chain: {}",
bhash,
e.kind()
@@ -527,8 +502,8 @@ impl NetToChainAdapter {
let now = Instant::now();
debug!(
LOGGER,
"adapter: process_block: ***** validating full chain state at {}", bhash,
"adapter: process_block: ***** validating full chain state at {}",
bhash,
);
self.chain()
@@ -536,7 +511,6 @@ impl NetToChainAdapter {
.expect("chain validation failed, hard stop");
debug!(
LOGGER,
"adapter: process_block: ***** done validating full chain state, took {}s",
now.elapsed().as_secs(),
);
@@ -558,7 +532,7 @@ impl NetToChainAdapter {
.name("compactor".to_string())
.spawn(move || {
if let Err(e) = chain.compact() {
error!(LOGGER, "Could not compact chain: {:?}", e);
error!("Could not compact chain: {:?}", e);
}
});
}
@@ -592,23 +566,19 @@ impl NetToChainAdapter {
match self.chain().block_exists(h) {
Ok(false) => match self.peers().get_connected_peer(addr) {
None => debug!(
LOGGER,
"send_block_request_to_peer: can't send request to peer {:?}, not connected",
addr
),
Some(peer) => {
if let Err(e) = f(&peer, h) {
error!(LOGGER, "send_block_request_to_peer: failed: {:?}", e)
error!("send_block_request_to_peer: failed: {:?}", e)
}
}
},
Ok(true) => debug!(
LOGGER,
"send_block_request_to_peer: block {} already known", h
),
Ok(true) => debug!("send_block_request_to_peer: block {} already known", h),
Err(e) => error!(
LOGGER,
"send_block_request_to_peer: failed to check block exists: {:?}", e
"send_block_request_to_peer: failed to check block exists: {:?}",
e
),
}
}
@@ -639,11 +609,10 @@ impl ChainAdapter for ChainToPoolAndNetAdapter {
return;
}
debug!(LOGGER, "adapter: block_accepted: {:?}", b.hash());
debug!("adapter: block_accepted: {:?}", b.hash());
if let Err(e) = self.tx_pool.write().reconcile_block(b) {
error!(
LOGGER,
"Pool could not update itself at block {}: {:?}",
b.hash(),
e,
+1 -5
View File
@@ -25,7 +25,6 @@ use core::{core, pow};
use p2p;
use pool;
use store;
use util::LOGGER;
use wallet;
/// Error type wrapping underlying module errors.
@@ -314,10 +313,7 @@ impl SyncState {
let mut status = self.current.write();
debug!(
LOGGER,
"sync_state: sync_status: {:?} -> {:?}", *status, new_status,
);
debug!("sync_state: sync_status: {:?} -> {:?}", *status, new_status,);
*status = new_status;
}