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:
+18
-34
@@ -30,7 +30,6 @@ use msg::{
|
||||
TxHashSetArchive, TxHashSetRequest, Type,
|
||||
};
|
||||
use types::{Error, NetAdapter};
|
||||
use util::LOGGER;
|
||||
|
||||
pub struct Protocol {
|
||||
adapter: Arc<NetAdapter>,
|
||||
@@ -52,10 +51,8 @@ impl MessageHandler for Protocol {
|
||||
// banned peers up correctly?
|
||||
if adapter.is_banned(self.addr.clone()) {
|
||||
debug!(
|
||||
LOGGER,
|
||||
"handler: consume: peer {:?} banned, received: {:?}, dropping.",
|
||||
self.addr,
|
||||
msg.header.msg_type,
|
||||
self.addr, msg.header.msg_type,
|
||||
);
|
||||
return Ok(None);
|
||||
}
|
||||
@@ -82,14 +79,14 @@ impl MessageHandler for Protocol {
|
||||
|
||||
Type::BanReason => {
|
||||
let ban_reason: BanReason = msg.body()?;
|
||||
error!(LOGGER, "handle_payload: BanReason {:?}", ban_reason);
|
||||
error!("handle_payload: BanReason {:?}", ban_reason);
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
Type::Transaction => {
|
||||
debug!(
|
||||
LOGGER,
|
||||
"handle_payload: received tx: msg_len: {}", msg.header.msg_len
|
||||
"handle_payload: received tx: msg_len: {}",
|
||||
msg.header.msg_len
|
||||
);
|
||||
let tx: core::Transaction = msg.body()?;
|
||||
adapter.transaction_received(tx, false);
|
||||
@@ -98,8 +95,8 @@ impl MessageHandler for Protocol {
|
||||
|
||||
Type::StemTransaction => {
|
||||
debug!(
|
||||
LOGGER,
|
||||
"handle_payload: received stem tx: msg_len: {}", msg.header.msg_len
|
||||
"handle_payload: received stem tx: msg_len: {}",
|
||||
msg.header.msg_len
|
||||
);
|
||||
let tx: core::Transaction = msg.body()?;
|
||||
adapter.transaction_received(tx, true);
|
||||
@@ -109,7 +106,6 @@ impl MessageHandler for Protocol {
|
||||
Type::GetBlock => {
|
||||
let h: Hash = msg.body()?;
|
||||
trace!(
|
||||
LOGGER,
|
||||
"handle_payload: Getblock: {}, msg_len: {}",
|
||||
h,
|
||||
msg.header.msg_len,
|
||||
@@ -124,8 +120,8 @@ impl MessageHandler for Protocol {
|
||||
|
||||
Type::Block => {
|
||||
debug!(
|
||||
LOGGER,
|
||||
"handle_payload: received block: msg_len: {}", msg.header.msg_len
|
||||
"handle_payload: received block: msg_len: {}",
|
||||
msg.header.msg_len
|
||||
);
|
||||
let b: core::Block = msg.body()?;
|
||||
|
||||
@@ -145,8 +141,8 @@ impl MessageHandler for Protocol {
|
||||
|
||||
Type::CompactBlock => {
|
||||
debug!(
|
||||
LOGGER,
|
||||
"handle_payload: received compact block: msg_len: {}", msg.header.msg_len
|
||||
"handle_payload: received compact block: msg_len: {}",
|
||||
msg.header.msg_len
|
||||
);
|
||||
let b: core::CompactBlock = msg.body()?;
|
||||
|
||||
@@ -218,8 +214,8 @@ impl MessageHandler for Protocol {
|
||||
Type::TxHashSetRequest => {
|
||||
let sm_req: TxHashSetRequest = msg.body()?;
|
||||
debug!(
|
||||
LOGGER,
|
||||
"handle_payload: txhashset req for {} at {}", sm_req.hash, sm_req.height
|
||||
"handle_payload: txhashset req for {} at {}",
|
||||
sm_req.hash, sm_req.height
|
||||
);
|
||||
|
||||
let txhashset = self.adapter.txhashset_read(sm_req.hash);
|
||||
@@ -244,15 +240,11 @@ impl MessageHandler for Protocol {
|
||||
Type::TxHashSetArchive => {
|
||||
let sm_arch: TxHashSetArchive = msg.body()?;
|
||||
debug!(
|
||||
LOGGER,
|
||||
"handle_payload: txhashset archive for {} at {}. size={}",
|
||||
sm_arch.hash,
|
||||
sm_arch.height,
|
||||
sm_arch.bytes,
|
||||
sm_arch.hash, sm_arch.height, sm_arch.bytes,
|
||||
);
|
||||
if !self.adapter.txhashset_receive_ready() {
|
||||
error!(
|
||||
LOGGER,
|
||||
"handle_payload: txhashset archive received but SyncStatus not on TxHashsetDownload",
|
||||
);
|
||||
return Err(Error::BadMessage);
|
||||
@@ -284,14 +276,13 @@ impl MessageHandler for Protocol {
|
||||
|
||||
if let Err(e) = save_txhashset_to_file(tmp.clone()) {
|
||||
error!(
|
||||
LOGGER,
|
||||
"handle_payload: txhashset archive save to file fail. err={:?}", e
|
||||
"handle_payload: txhashset archive save to file fail. err={:?}",
|
||||
e
|
||||
);
|
||||
return Err(e);
|
||||
}
|
||||
|
||||
trace!(
|
||||
LOGGER,
|
||||
"handle_payload: txhashset archive save to file {:?} success",
|
||||
tmp,
|
||||
);
|
||||
@@ -302,18 +293,15 @@ impl MessageHandler for Protocol {
|
||||
.txhashset_write(sm_arch.hash, tmp_zip, self.addr);
|
||||
|
||||
debug!(
|
||||
LOGGER,
|
||||
"handle_payload: txhashset archive for {} at {}, DONE. Data Ok: {}",
|
||||
sm_arch.hash,
|
||||
sm_arch.height,
|
||||
res
|
||||
sm_arch.hash, sm_arch.height, res
|
||||
);
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
_ => {
|
||||
debug!(LOGGER, "unknown message type {:?}", msg.header.msg_type);
|
||||
debug!("unknown message type {:?}", msg.header.msg_type);
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
@@ -341,12 +329,8 @@ fn headers_header_size(conn: &mut TcpStream, msg_len: u64) -> Result<u64, Error>
|
||||
let max_size = min_size + 6;
|
||||
if average_header_size < min_size as u64 || average_header_size > max_size as u64 {
|
||||
debug!(
|
||||
LOGGER,
|
||||
"headers_header_size - size of Vec: {}, average_header_size: {}, min: {}, max: {}",
|
||||
total_headers,
|
||||
average_header_size,
|
||||
min_size,
|
||||
max_size,
|
||||
total_headers, average_header_size, min_size, max_size,
|
||||
);
|
||||
return Err(Error::Connection(io::Error::new(
|
||||
io::ErrorKind::InvalidData,
|
||||
|
||||
Reference in New Issue
Block a user