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
+6 -12
View File
@@ -28,7 +28,7 @@ use core::core::verifier_cache::VerifierCache;
use core::{consensus, core, ser};
use keychain::{ExtKeychain, Identifier, Keychain};
use pool;
use util::{self, LOGGER};
use util;
use wallet::{self, BlockFees};
// Ensure a block suitable for mining is built and returned
@@ -55,24 +55,22 @@ pub fn get_block(
self::Error::Chain(c) => match c.kind() {
chain::ErrorKind::DuplicateCommitment(_) => {
debug!(
LOGGER,
"Duplicate commit for potential coinbase detected. Trying next derivation."
);
}
_ => {
error!(LOGGER, "Chain Error: {}", c);
error!("Chain Error: {}", c);
}
},
self::Error::Wallet(_) => {
error!(
LOGGER,
"Error building new block: Can't connect to wallet listener at {:?}; will retry",
wallet_listener_url.as_ref().unwrap()
);
thread::sleep(Duration::from_secs(wallet_retry_interval));
}
ae => {
warn!(LOGGER, "Error building new block: {:?}. Retrying.", ae);
warn!("Error building new block: {:?}. Retrying.", ae);
}
}
thread::sleep(Duration::from_millis(100));
@@ -134,7 +132,6 @@ fn build_block(
let b_difficulty = (b.header.total_difficulty() - head.total_difficulty()).to_num();
debug!(
LOGGER,
"Built new block with {} inputs and {} outputs, network difficulty: {}, cumulative difficulty {}",
b.inputs().len(),
b.outputs().len(),
@@ -159,10 +156,7 @@ fn build_block(
//Some other issue, possibly duplicate kernel
_ => {
error!(
LOGGER,
"Error setting txhashset root to build a block: {:?}", e
);
error!("Error setting txhashset root to build a block: {:?}", e);
Err(Error::Chain(
chain::ErrorKind::Other(format!("{:?}", e)).into(),
))
@@ -176,7 +170,7 @@ fn build_block(
/// Probably only want to do this when testing.
///
fn burn_reward(block_fees: BlockFees) -> Result<(core::Output, core::TxKernel, BlockFees), Error> {
warn!(LOGGER, "Burning block fees: {:?}", block_fees);
warn!("Burning block fees: {:?}", block_fees);
let keychain = ExtKeychain::from_random_seed().unwrap();
let key_id = ExtKeychain::derive_key_id(1, 1, 0, 0, 0);
let (out, kernel) =
@@ -209,7 +203,7 @@ fn get_coinbase(
..block_fees
};
debug!(LOGGER, "get_coinbase: {:?}", block_fees);
debug!("get_coinbase: {:?}", block_fees);
return Ok((output, kernel, block_fees));
}
}
+20 -46
View File
@@ -35,7 +35,7 @@ use core::{pow, ser};
use keychain;
use mining::mine_block;
use pool;
use util::{self, LOGGER};
use util;
// ----------------------------------------
// http://www.jsonrpc.org/specification
@@ -114,7 +114,6 @@ fn accept_workers(
match stream {
Ok(stream) => {
warn!(
LOGGER,
"(Server ID: {}) New connection: {}",
id,
stream.peer_addr().unwrap()
@@ -135,10 +134,7 @@ fn accept_workers(
worker_id = worker_id + 1;
}
Err(e) => {
warn!(
LOGGER,
"(Server ID: {}) Error accepting connection: {:?}", id, e
);
warn!("(Server ID: {}) Error accepting connection: {:?}", id, e);
}
}
}
@@ -185,8 +181,8 @@ impl Worker {
}
Err(e) => {
warn!(
LOGGER,
"(Server ID: {}) Error in connection with stratum client: {}", self.id, e
"(Server ID: {}) Error in connection with stratum client: {}",
self.id, e
);
self.error = true;
return None;
@@ -206,16 +202,16 @@ impl Worker {
Ok(_) => {}
Err(e) => {
warn!(
LOGGER,
"(Server ID: {}) Error in connection with stratum client: {}", self.id, e
"(Server ID: {}) Error in connection with stratum client: {}",
self.id, e
);
self.error = true;
}
},
Err(e) => {
warn!(
LOGGER,
"(Server ID: {}) Error in connection with stratum client: {}", self.id, e
"(Server ID: {}) Error in connection with stratum client: {}",
self.id, e
);
self.error = true;
return;
@@ -296,7 +292,6 @@ impl StratumServer {
Err(e) => {
// not a valid JSON RpcRequest - disconnect the worker
warn!(
LOGGER,
"(Server ID: {}) Failed to parse JSONRpc: {} - {:?}",
self.id,
e.description(),
@@ -409,11 +404,8 @@ impl StratumServer {
let job_template = self.build_block_template();
let response = serde_json::to_value(&job_template).unwrap();
debug!(
LOGGER,
"(Server ID: {}) sending block {} with id {} to single worker",
self.id,
job_template.height,
job_template.job_id,
self.id, job_template.height, job_template.job_id,
);
return Ok(response);
}
@@ -452,8 +444,8 @@ impl StratumServer {
if params.height != self.current_block_versions.last().unwrap().header.height {
// Return error status
error!(
LOGGER,
"(Server ID: {}) Share at height {} submitted too late", self.id, params.height,
"(Server ID: {}) Share at height {} submitted too late",
self.id, params.height,
);
worker_stats.num_stale += 1;
let e = RpcError {
@@ -467,11 +459,8 @@ impl StratumServer {
if b.is_none() {
// Return error status
error!(
LOGGER,
"(Server ID: {}) Failed to validate solution at height {}: invalid job_id {}",
self.id,
params.height,
params.job_id,
self.id, params.height, params.job_id,
);
worker_stats.num_rejected += 1;
let e = RpcError {
@@ -491,11 +480,8 @@ impl StratumServer {
if share_difficulty < self.minimum_share_difficulty {
// Return error status
error!(
LOGGER,
"(Server ID: {}) Share rejected due to low difficulty: {}/{}",
self.id,
share_difficulty,
self.minimum_share_difficulty,
self.id, share_difficulty, self.minimum_share_difficulty,
);
worker_stats.num_rejected += 1;
let e = RpcError {
@@ -511,7 +497,6 @@ impl StratumServer {
if let Err(e) = res {
// Return error status
error!(
LOGGER,
"(Server ID: {}) Failed to validate solution at height {}: {}: {}",
self.id,
params.height,
@@ -528,15 +513,14 @@ impl StratumServer {
share_is_block = true;
// Log message to make it obvious we found a block
warn!(
LOGGER,
"(Server ID: {}) Solution Found for block {} - Yay!!!", self.id, params.height
"(Server ID: {}) Solution Found for block {} - Yay!!!",
self.id, params.height
);
} else {
// Do some validation but dont submit
if !pow::verify_size(&b.header, b.header.pow.proof.edge_bits).is_ok() {
// Return error status
error!(
LOGGER,
"(Server ID: {}) Failed to validate share at height {} with nonce {} using job_id {}",
self.id,
params.height,
@@ -557,7 +541,6 @@ impl StratumServer {
Some(login) => login.clone(),
};
info!(
LOGGER,
"(Server ID: {}) Got share for block: hash {}, height {}, nonce {}, difficulty {}/{}, submitted by {}",
self.id,
b.hash(),
@@ -588,11 +571,9 @@ impl StratumServer {
for num in start..workers_l.len() {
if workers_l[num].error == true {
warn!(
LOGGER,
"(Server ID: {}) Dropping worker: {}",
self.id,
workers_l[num].id;
);
"(Server ID: {}) Dropping worker: {}",
self.id, workers_l[num].id
);
// Update worker stats
let mut stratum_stats = stratum_stats.write();
let worker_stats_id = stratum_stats
@@ -631,11 +612,8 @@ impl StratumServer {
};
let job_request_json = serde_json::to_string(&job_request).unwrap();
debug!(
LOGGER,
"(Server ID: {}) sending block {} with id {} to stratum clients",
self.id,
job_template.height,
job_template.job_id,
self.id, job_template.height, job_template.job_id,
);
// Push the new block to all connected clients
// NOTE: We do not give a unique nonce (should we?) so miners need
@@ -659,11 +637,8 @@ impl StratumServer {
sync_state: Arc<SyncState>,
) {
info!(
LOGGER,
"(Server ID: {}) Starting stratum server with edge_bits = {}, proof_size = {}",
self.id,
edge_bits,
proof_size
self.id, edge_bits, proof_size
);
self.sync_state = sync_state;
@@ -698,7 +673,6 @@ impl StratumServer {
}
warn!(
LOGGER,
"Stratum server started on {}",
self.config.stratum_server_addr.clone().unwrap()
);
+9 -19
View File
@@ -31,7 +31,6 @@ use core::global;
use core::pow::PoWContext;
use mining::mine_block;
use pool;
use util::LOGGER;
pub struct Miner {
config: StratumServerConfig,
@@ -85,7 +84,6 @@ impl Miner {
let deadline = Utc::now().timestamp() + attempt_time_per_block as i64;
debug!(
LOGGER,
"(Server ID: {}) Mining Cuckoo{} for max {}s on {} @ {} [{}].",
self.debug_output_id,
global::min_edge_bits(),
@@ -116,10 +114,8 @@ impl Miner {
}
debug!(
LOGGER,
"(Server ID: {}) No solution found after {} iterations, continuing...",
self.debug_output_id,
iter_count
self.debug_output_id, iter_count
);
false
}
@@ -128,8 +124,8 @@ impl Miner {
/// chain anytime required and looking for PoW solution.
pub fn run_loop(&self, wallet_listener_url: Option<String>) {
info!(
LOGGER,
"(Server ID: {}) Starting test miner loop.", self.debug_output_id
"(Server ID: {}) Starting test miner loop.",
self.debug_output_id
);
// iteration, we keep the returned derivation to provide it back when
@@ -137,7 +133,7 @@ impl Miner {
let mut key_id = None;
while !self.stop.load(Ordering::Relaxed) {
trace!(LOGGER, "in miner loop. key_id: {:?}", key_id);
trace!("in miner loop. key_id: {:?}", key_id);
// get the latest chain state and build a block on top of it
let head = self.chain.head_header().unwrap();
@@ -161,7 +157,6 @@ impl Miner {
// we found a solution, push our block through the chain processing pipeline
if sol {
info!(
LOGGER,
"(Server ID: {}) Found valid proof of work, adding block {}.",
self.debug_output_id,
b.hash()
@@ -169,26 +164,21 @@ impl Miner {
let res = self.chain.process_block(b, chain::Options::MINE);
if let Err(e) = res {
error!(
LOGGER,
"(Server ID: {}) Error validating mined block: {:?}",
self.debug_output_id,
e
self.debug_output_id, e
);
}
trace!(LOGGER, "resetting key_id in miner to None");
trace!("resetting key_id in miner to None");
key_id = None;
} else {
debug!(
LOGGER,
"setting pubkey in miner to pubkey from block_fees - {:?}", block_fees
"setting pubkey in miner to pubkey from block_fees - {:?}",
block_fees
);
key_id = block_fees.key_id();
}
}
info!(
LOGGER,
"(Server ID: {}) test miner exit.", self.debug_output_id
);
info!("(Server ID: {}) test miner exit.", self.debug_output_id);
}
}