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 -14
View File
@@ -26,8 +26,8 @@ use api;
use error::{Error, ErrorKind};
use libtx::slate::Slate;
use libwallet;
use util;
use util::secp::pedersen;
use util::{self, LOGGER};
#[derive(Clone)]
pub struct HTTPWalletClient {
@@ -65,11 +65,11 @@ impl WalletClient for HTTPWalletClient {
match single_create_coinbase(&url, &block_fees) {
Err(e) => {
error!(
LOGGER,
"Failed to get coinbase from {}. Run grin wallet listen?", url
"Failed to get coinbase from {}. Run grin wallet listen?",
url
);
error!(LOGGER, "Underlying Error: {}", e.cause().unwrap());
error!(LOGGER, "Backtrace: {}", e.backtrace().unwrap());
error!("Underlying Error: {}", e.cause().unwrap());
error!("Backtrace: {}", e.backtrace().unwrap());
Err(libwallet::ErrorKind::ClientCallback(
"Failed to get coinbase",
))?
@@ -85,11 +85,11 @@ impl WalletClient for HTTPWalletClient {
"dest formatted as {} but send -d expected stdout or http://IP:port",
dest
);
error!(LOGGER, "{}", err_str,);
error!("{}", err_str,);
Err(libwallet::ErrorKind::Uri)?
}
let url = format!("{}/v1/wallet/foreign/receive_tx", dest);
debug!(LOGGER, "Posting transaction slate to {}", url);
debug!("Posting transaction slate to {}", url);
let res = api::client::post(url.as_str(), None, slate).context(
libwallet::ErrorKind::ClientCallback("Posting transaction slate"),
@@ -153,7 +153,7 @@ impl WalletClient for HTTPWalletClient {
let results = match rt.block_on(task) {
Ok(outputs) => outputs,
Err(e) => {
error!(LOGGER, "Outputs by id failed: {}", e);
error!("Outputs by id failed: {}", e);
return Err(libwallet::ErrorKind::ClientCallback("Error from server"))?;
}
};
@@ -209,8 +209,8 @@ impl WalletClient for HTTPWalletClient {
Err(e) => {
// if we got anything other than 200 back from server, bye
error!(
LOGGER,
"get_outputs_by_pmmr_index: unable to contact API {}. Error: {}", addr, e
"get_outputs_by_pmmr_index: unable to contact API {}. Error: {}",
addr, e
);
Err(libwallet::ErrorKind::ClientCallback(
"unable to contact api",
@@ -226,11 +226,11 @@ pub fn create_coinbase(dest: &str, block_fees: &BlockFees) -> Result<CbData, Err
match single_create_coinbase(&url, &block_fees) {
Err(e) => {
error!(
LOGGER,
"Failed to get coinbase from {}. Run grin wallet listen?", url
"Failed to get coinbase from {}. Run grin wallet listen?",
url
);
error!(LOGGER, "Underlying Error: {}", e.cause().unwrap());
error!(LOGGER, "Backtrace: {}", e.backtrace().unwrap());
error!("Underlying Error: {}", e.cause().unwrap());
error!("Backtrace: {}", e.backtrace().unwrap());
Err(e)?
}
Ok(res) => Ok(res),
+7 -10
View File
@@ -27,8 +27,7 @@ use uuid::Uuid;
use failure::ResultExt;
use keychain::{self, Identifier, Keychain};
use util::secp::pedersen;
use util::LOGGER;
use util::secp::pedersen
use error::{Error, ErrorKind};
@@ -168,11 +167,10 @@ where
// delete the lock file
if let Err(e) = fs::remove_dir(&self.lock_file_path) {
error!(
LOGGER,
"Could not remove wallet lock file. Maybe insufficient rights? {:?} ", e
);
}
info!(LOGGER, "... released wallet lock");
info!("... released wallet lock");
}
}
@@ -224,7 +222,7 @@ where
/// Close wallet and remove any stored credentials (TBD)
fn close(&mut self) -> Result<(), libwallet::Error> {
debug!(LOGGER, "Closing wallet keychain");
debug!("Closing wallet keychain");
self.keychain = None;
Ok(())
}
@@ -352,14 +350,14 @@ where
fn lock(&self) -> Result<(), libwallet::Error> {
// create directory if it doesn't exist
fs::create_dir_all(self.config.data_file_dir.clone()).unwrap_or_else(|why| {
info!(LOGGER, "! {:?}", why.kind());
info!("! {:?}", why.kind());
});
info!(LOGGER, "Acquiring wallet lock ...");
info!("Acquiring wallet lock ...");
let lock_file_path = self.lock_file_path.clone();
let action = || {
trace!(LOGGER, "making lock file for wallet lock");
trace!("making lock file for wallet lock");
fs::create_dir(&lock_file_path)
};
@@ -377,7 +375,6 @@ where
Ok(_) => Ok(()),
Err(e) => {
error!(
LOGGER,
"Failed to acquire wallet lock file (multiple retries)",
);
Err(e.into())
@@ -390,7 +387,7 @@ where
fn read_or_create_paths(&mut self) -> Result<(), Error> {
if !Path::new(&self.config.data_file_dir.clone()).exists() {
fs::create_dir_all(&self.config.data_file_dir.clone()).unwrap_or_else(|why| {
info!(LOGGER, "! {:?}", why.kind());
info!("! {:?}", why.kind());
});
}
if Path::new(&self.data_file_path.clone()).exists() {
+1 -1
View File
@@ -24,7 +24,7 @@ extern crate serde;
extern crate serde_derive;
extern crate serde_json;
#[macro_use]
extern crate slog;
extern crate log;
extern crate chrono;
extern crate term;
extern crate url;
+4 -8
View File
@@ -30,7 +30,6 @@ use util::{kernel_sig_msg, secp};
use core::core::{Input, Output, OutputFeatures, Transaction, TxKernel};
use keychain::{self, BlindSum, BlindingFactor, Identifier, Keychain};
use libtx::{aggsig, proof};
use util::LOGGER;
/// Context information available to transaction combinators.
pub struct Context<'a, K: 'a>
@@ -67,8 +66,8 @@ where
K: Keychain,
{
debug!(
LOGGER,
"Building input (spending regular output): {}, {}", value, key_id
"Building input (spending regular output): {}, {}",
value, key_id
);
build_input(value, OutputFeatures::DEFAULT_OUTPUT, key_id)
}
@@ -78,10 +77,7 @@ pub fn coinbase_input<K>(value: u64, key_id: Identifier) -> Box<Append<K>>
where
K: Keychain,
{
debug!(
LOGGER,
"Building input (spending coinbase): {}, {}", value, key_id
);
debug!("Building input (spending coinbase): {}, {}", value, key_id);
build_input(value, OutputFeatures::COINBASE_OUTPUT, key_id)
}
@@ -95,7 +91,7 @@ where
move |build, (tx, kern, sum)| -> (Transaction, TxKernel, BlindSum) {
let commit = build.keychain.commit(value, &key_id).unwrap();
debug!(LOGGER, "Building output: {}, {:?}", value, commit);
debug!("Building output: {}, {:?}", value, commit);
let rproof = proof::create(build.keychain, value, &key_id, commit, None).unwrap();
+2 -2
View File
@@ -21,7 +21,7 @@ use core::core::KernelFeatures;
use core::core::{Output, OutputFeatures, TxKernel};
use libtx::error::Error;
use libtx::{aggsig, proof};
use util::{kernel_sig_msg, secp, static_secp_instance, LOGGER};
use util::{kernel_sig_msg, secp, static_secp_instance};
/// output a reward output
pub fn output<K>(
@@ -36,7 +36,7 @@ where
let value = reward(fees);
let commit = keychain.commit(value, key_id)?;
trace!(LOGGER, "Block reward - Pedersen Commit is: {:?}", commit,);
trace!("Block reward - Pedersen Commit is: {:?}", commit,);
let rproof = proof::create(keychain, value, key_id, commit, None)?;
+3 -3
View File
@@ -27,9 +27,9 @@ use keychain::{BlindSum, BlindingFactor, Keychain};
use libtx::error::{Error, ErrorKind};
use libtx::{aggsig, build, tx_fee};
use util::secp;
use util::secp::key::{PublicKey, SecretKey};
use util::secp::Signature;
use util::{secp, LOGGER};
/// Public data for each participant in the slate
@@ -289,7 +289,7 @@ impl Slate {
amount_to_hr_string(fee, false),
amount_to_hr_string(self.amount + self.fee, false)
);
info!(LOGGER, "{}", reason);
info!("{}", reason);
return Err(ErrorKind::Fee(reason.to_string()))?;
}
@@ -395,7 +395,7 @@ impl Slate {
final_tx.kernels_mut()[0].excess_sig = final_sig.clone();
// confirm the kernel verifies successfully before proceeding
debug!(LOGGER, "Validating final transaction");
debug!("Validating final transaction");
final_tx.kernels()[0].verify()?;
// confirm the overall transaction is valid (including the updated kernel)
+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(),
+2 -4
View File
@@ -26,7 +26,6 @@ use error::{Error, ErrorKind};
use failure::ResultExt;
use keychain::Keychain;
use util;
use util::LOGGER;
pub const SEED_FILE: &'static str = "wallet.seed";
@@ -118,7 +117,7 @@ impl WalletSeed {
wallet_config.data_file_dir, MAIN_SEPARATOR, SEED_FILE,
);
debug!(LOGGER, "Generating wallet seed file at: {}", seed_file_path);
debug!("Generating wallet seed file at: {}", seed_file_path);
if Path::new(seed_file_path).exists() {
Err(ErrorKind::WalletSeedExists)?
@@ -140,7 +139,7 @@ impl WalletSeed {
wallet_config.data_file_dir, MAIN_SEPARATOR, SEED_FILE,
);
debug!(LOGGER, "Using wallet seed file at: {}", seed_file_path,);
debug!("Using wallet seed file at: {}", seed_file_path,);
if Path::new(seed_file_path).exists() {
let mut file = File::open(seed_file_path).context(ErrorKind::IO)?;
@@ -150,7 +149,6 @@ impl WalletSeed {
Ok(wallet_seed)
} else {
error!(
LOGGER,
"wallet seed file {} could not be opened (grin wallet init). \
Run \"grin wallet init\" to initialize a new wallet.",
seed_file_path