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
+14 -17
View File
@@ -36,8 +36,8 @@ use libwallet::types::{
WalletClient, WalletInfo,
};
use libwallet::{Error, ErrorKind};
use util;
use util::secp::pedersen;
use util::{self, LOGGER};
/// Wrapper around internal API functions, containing a reference to
/// the wallet/keychain that they're acting upon
@@ -188,7 +188,6 @@ where
Ok(s) => s,
Err(e) => {
error!(
LOGGER,
"Communication with receiver failed on SenderInitiation send. Aborting transaction {:?}",
e,
);
@@ -321,11 +320,10 @@ where
};
let res = client.post_tx(&TxWrapper { tx_hex: tx_hex }, fluff);
if let Err(e) = res {
error!(LOGGER, "api: post_tx: failed with error: {}", e);
error!("api: post_tx: failed with error: {}", e);
Err(e)
} else {
debug!(
LOGGER,
"api: post_tx: successfully posted tx: {}, fluff? {}",
slate.tx.hash(),
fluff
@@ -351,14 +349,14 @@ where
};
if confirmed {
warn!(
LOGGER,
"api: dump_stored_tx: transaction at {} is already confirmed.", tx_id
"api: dump_stored_tx: transaction at {} is already confirmed.",
tx_id
);
}
if tx_hex.is_none() {
error!(
LOGGER,
"api: dump_stored_tx: completed transaction at {} does not exist.", tx_id
"api: dump_stored_tx: completed transaction at {} does not exist.",
tx_id
);
return Err(ErrorKind::TransactionBuildingNotCompleted(tx_id))?;
}
@@ -386,15 +384,15 @@ where
};
if confirmed {
error!(
LOGGER,
"api: repost_tx: transaction at {} is confirmed. NOT resending.", tx_id
"api: repost_tx: transaction at {} is confirmed. NOT resending.",
tx_id
);
return Err(ErrorKind::TransactionAlreadyConfirmed)?;
}
if tx_hex.is_none() {
error!(
LOGGER,
"api: repost_tx: completed transaction at {} does not exist.", tx_id
"api: repost_tx: completed transaction at {} does not exist.",
tx_id
);
return Err(ErrorKind::TransactionBuildingNotCompleted(tx_id))?;
}
@@ -406,12 +404,12 @@ where
fluff,
);
if let Err(e) = res {
error!(LOGGER, "api: repost_tx: failed with error: {}", e);
error!("api: repost_tx: failed with error: {}", e);
Err(e)
} else {
debug!(
LOGGER,
"api: repost_tx: successfully posted tx at: {}, fluff? {}", tx_id, fluff
"api: repost_tx: successfully posted tx at: {}, fluff? {}",
tx_id, fluff
);
Ok(())
}
@@ -541,11 +539,10 @@ where
w.close()?;
if let Err(e) = res {
error!(LOGGER, "api: receive_tx: failed with error: {}", e);
error!("api: receive_tx: failed with error: {}", e);
Err(e)
} else {
debug!(
LOGGER,
"api: receive_tx: successfully received tx: {}",
slate.tx.hash()
);
+13 -13
View File
@@ -37,7 +37,7 @@ use std::sync::Arc;
use url::form_urlencoded;
use util::secp::pedersen;
use util::Mutex;
use util::{to_base64, LOGGER};
use util::to_base64;
/// Instantiate wallet Owner API for a single-use (command line) call
/// Return a function containing a loaded API context to call
@@ -95,7 +95,7 @@ where
.map_err(|_| ErrorKind::GenericError("Router failed to add route".to_string()))?;
let mut apis = ApiServer::new();
info!(LOGGER, "Starting HTTP Owner API server at {}.", addr);
info!("Starting HTTP Owner API server at {}.", addr);
let socket_addr: SocketAddr = addr.parse().expect("unable to parse socket address");
let api_thread =
apis.start(socket_addr, router, tls_config)
@@ -127,7 +127,7 @@ where
.map_err(|_| ErrorKind::GenericError("Router failed to add route".to_string()))?;
let mut apis = ApiServer::new();
info!(LOGGER, "Starting HTTP Foreign API server at {}.", addr);
info!("Starting HTTP Foreign API server at {}.", addr);
let socket_addr: SocketAddr = addr.parse().expect("unable to parse socket address");
let api_thread =
apis.start(socket_addr, router, tls_config)
@@ -226,12 +226,12 @@ where
Ok(id) => match api.dump_stored_tx(id, false, "") {
Ok(tx) => Ok(tx),
Err(e) => {
error!(LOGGER, "dump_stored_tx: failed with error: {}", e);
error!("dump_stored_tx: failed with error: {}", e);
Err(e)
}
},
Err(e) => {
error!(LOGGER, "dump_stored_tx: could not parse id: {}", e);
error!("dump_stored_tx: could not parse id: {}", e);
Err(ErrorKind::TransactionDumpError(
"dump_stored_tx: cannot dump transaction. Could not parse id in request.",
).into())
@@ -307,7 +307,7 @@ where
args.selection_strategy_is_use_all,
)
} else {
error!(LOGGER, "unsupported payment method: {}", args.method);
error!("unsupported payment method: {}", args.method);
return Err(ErrorKind::ClientCallback("unsupported payment method"))?;
}
}))
@@ -322,7 +322,7 @@ where
parse_body(req).and_then(move |mut slate| match api.finalize_tx(&mut slate) {
Ok(_) => ok(slate.clone()),
Err(e) => {
error!(LOGGER, "finalize_tx: failed with error: {}", e);
error!("finalize_tx: failed with error: {}", e);
err(e)
}
}),
@@ -340,12 +340,12 @@ where
Ok(id) => match api.cancel_tx(id) {
Ok(_) => ok(()),
Err(e) => {
error!(LOGGER, "cancel_tx: failed with error: {}", e);
error!("cancel_tx: failed with error: {}", e);
err(e)
}
},
Err(e) => {
error!(LOGGER, "cancel_tx: could not parse id: {}", e);
error!("cancel_tx: could not parse id: {}", e);
err(ErrorKind::TransactionCancellationError(
"cancel_tx: cannot cancel transaction. Could not parse id in request.",
).into())
@@ -443,7 +443,7 @@ where
match self.handle_get_request(&req) {
Ok(r) => Box::new(ok(r)),
Err(e) => {
error!(LOGGER, "Request Error: {:?}", e);
error!("Request Error: {:?}", e);
Box::new(ok(create_error_response(e)))
}
}
@@ -454,7 +454,7 @@ where
self.handle_post_request(req)
.and_then(|r| ok(r))
.or_else(|e| {
error!(LOGGER, "Request Error: {:?}", e);
error!("Request Error: {:?}", e);
ok(create_error_response(e))
}),
)
@@ -511,7 +511,7 @@ where
parse_body(req).and_then(move |mut slate| match api.receive_tx(&mut slate) {
Ok(_) => ok(slate.clone()),
Err(e) => {
error!(LOGGER, "receive_tx: failed with error: {}", e);
error!("receive_tx: failed with error: {}", e);
err(e)
}
}),
@@ -548,7 +548,7 @@ where
{
fn post(&self, req: Request<Body>) -> ResponseFuture {
Box::new(self.handle_request(req).and_then(|r| ok(r)).or_else(|e| {
error!(LOGGER, "Request Error: {:?}", e);
error!("Request Error: {:?}", e);
ok(create_error_response(e))
}))
}
+3 -13
View File
@@ -21,7 +21,6 @@ use libwallet::types::*;
use libwallet::Error;
use std::collections::HashMap;
use util::secp::{key::SecretKey, pedersen};
use util::LOGGER;
/// Utility struct for return values from below
struct OutputResult {
@@ -55,7 +54,6 @@ where
let mut wallet_outputs: Vec<OutputResult> = Vec::new();
info!(
LOGGER,
"Scanning {} outputs in the current Grin utxo set",
outputs.len(),
);
@@ -70,10 +68,7 @@ where
continue;
}
info!(
LOGGER,
"Output found: {:?}, amount: {:?}", commit, info.value
);
info!("Output found: {:?}, amount: {:?}", commit, info.value);
let lock_height = if *is_coinbase {
*height + global::coinbase_maturity()
@@ -109,14 +104,11 @@ where
// Don't proceed if wallet_data has anything in it
let is_empty = wallet.iter().next().is_none();
if !is_empty {
error!(
LOGGER,
"Not restoring. Please back up and remove existing db directory first."
);
error!("Not restoring. Please back up and remove existing db directory first.");
return Ok(());
}
info!(LOGGER, "Starting restore.");
info!("Starting restore.");
let batch_size = 1000;
let mut start_index = 1;
@@ -126,7 +118,6 @@ where
.client()
.get_outputs_by_pmmr_index(start_index, batch_size)?;
info!(
LOGGER,
"Retrieved {} outputs, up to index {}. (Highest index: {})",
outputs.len(),
highest_index,
@@ -142,7 +133,6 @@ where
}
info!(
LOGGER,
"Identified {} wallet_outputs as belonging to this wallet",
result_vec.len(),
);
+3 -9
View File
@@ -20,8 +20,6 @@ use libwallet::error::{Error, ErrorKind};
use libwallet::internal::keys;
use libwallet::types::*;
use util::LOGGER;
/// Initialize a transaction on the sender side, returns a corresponding
/// libwallet transaction slate with the appropriate inputs selected,
/// and saves the private wallet identifiers of our selected outputs
@@ -356,14 +354,11 @@ where
let mut change_amounts_derivations = vec![];
if change == 0 {
debug!(
LOGGER,
"No change (sending exactly amount + fee), no change outputs to build"
);
debug!("No change (sending exactly amount + fee), no change outputs to build");
} else {
debug!(
LOGGER,
"Building change outputs: total change: {} ({} outputs)", change, num_change_outputs
"Building change outputs: total change: {} ({} outputs)",
change, num_change_outputs
);
let part_change = change / num_change_outputs as u64;
@@ -442,7 +437,6 @@ where
// coins = the amount.
if let Some(outputs) = select_from(amount, false, eligible.clone()) {
debug!(
LOGGER,
"Extending maximum number of outputs. {} outputs selected.",
outputs.len()
);
+1 -2
View File
@@ -25,7 +25,6 @@ use libtx::{build, tx_fee};
use libwallet::internal::{selection, updater};
use libwallet::types::{Context, TxLogEntryType, WalletBackend, WalletClient};
use libwallet::{Error, ErrorKind};
use util::LOGGER;
/// Receive a transaction, modifying the slate accordingly (which can then be
/// sent back to sender for posting)
@@ -225,7 +224,7 @@ where
parent_key_id,
);
debug!(LOGGER, "selected some coins - {}", coins.len());
debug!("selected some coins - {}", coins.len());
let fee = tx_fee(coins.len(), 2, 1, None);
let num_change_outputs = 1;
+4 -9
View File
@@ -30,8 +30,8 @@ use libwallet::types::{
BlockFees, CbData, OutputData, OutputStatus, TxLogEntry, TxLogEntryType, WalletBackend,
WalletClient, WalletInfo,
};
use util;
use util::secp::pedersen;
use util::{self, LOGGER};
/// Retrieve all of the outputs (doesn't attempt to update from node)
pub fn retrieve_outputs<T: ?Sized, C, K>(
@@ -201,14 +201,10 @@ where
// these changes as the chain is syncing, incorrect or forking
if height < last_confirmed_height {
warn!(
LOGGER,
"Not updating outputs as the height of the node's chain \
is less than the last reported wallet update height."
);
warn!(
LOGGER,
"Please wait for sync on node to complete or fork to resolve and try again."
);
warn!("Please wait for sync on node to complete or fork to resolve and try again.");
return Ok(());
}
let mut batch = wallet.batch()?;
@@ -274,7 +270,7 @@ where
C: WalletClient,
K: Keychain,
{
debug!(LOGGER, "Refreshing wallet outputs");
debug!("Refreshing wallet outputs");
// build a local map of wallet outputs keyed by commit
// and a list of outputs we want to query the node for
@@ -423,7 +419,6 @@ where
}
debug!(
LOGGER,
"receive_coinbase: built candidate output - {:?}, {}",
key_id.clone(),
key_id,
@@ -432,7 +427,7 @@ where
let mut block_fees = block_fees.clone();
block_fees.key_id = Some(key_id.clone());
debug!(LOGGER, "receive_coinbase: {:?}", block_fees);
debug!("receive_coinbase: {:?}", block_fees);
let (out, kern) = reward::output(
wallet.keychain(),