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:
@@ -29,7 +29,6 @@ use core::global;
|
||||
use p2p::Seeding;
|
||||
use servers;
|
||||
use tui::ui;
|
||||
use util::LOGGER;
|
||||
|
||||
/// wrap below to allow UI to clean up on stop
|
||||
fn start_server(config: servers::ServerConfig) {
|
||||
@@ -37,9 +36,9 @@ fn start_server(config: servers::ServerConfig) {
|
||||
// Just kill process for now, otherwise the process
|
||||
// hangs around until sigint because the API server
|
||||
// currently has no shutdown facility
|
||||
warn!(LOGGER, "Shutting down...");
|
||||
warn!("Shutting down...");
|
||||
thread::sleep(Duration::from_millis(1000));
|
||||
warn!(LOGGER, "Shutdown complete.");
|
||||
warn!("Shutdown complete.");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -47,7 +46,7 @@ fn start_server_tui(config: servers::ServerConfig) {
|
||||
// Run the UI controller.. here for now for simplicity to access
|
||||
// everything it might need
|
||||
if config.run_tui.is_some() && config.run_tui.unwrap() {
|
||||
warn!(LOGGER, "Starting GRIN in UI mode...");
|
||||
warn!("Starting GRIN in UI mode...");
|
||||
servers::Server::start(config, |serv: Arc<servers::Server>| {
|
||||
let running = Arc::new(AtomicBool::new(true));
|
||||
let _ = thread::Builder::new()
|
||||
@@ -60,7 +59,7 @@ fn start_server_tui(config: servers::ServerConfig) {
|
||||
});
|
||||
}).unwrap();
|
||||
} else {
|
||||
warn!(LOGGER, "Starting GRIN w/o UI...");
|
||||
warn!("Starting GRIN w/o UI...");
|
||||
servers::Server::start(config, |serv: Arc<servers::Server>| {
|
||||
let running = Arc::new(AtomicBool::new(true));
|
||||
let r = running.clone();
|
||||
@@ -70,7 +69,7 @@ fn start_server_tui(config: servers::ServerConfig) {
|
||||
while running.load(Ordering::SeqCst) {
|
||||
thread::sleep(Duration::from_secs(1));
|
||||
}
|
||||
warn!(LOGGER, "Received SIGINT (Ctrl+C) or SIGTERM (kill).");
|
||||
warn!("Received SIGINT (Ctrl+C) or SIGTERM (kill).");
|
||||
serv.stop();
|
||||
}).unwrap();
|
||||
}
|
||||
@@ -170,8 +169,8 @@ pub fn server_command(server_args: Option<&ArgMatches>, mut global_config: Globa
|
||||
}
|
||||
});
|
||||
match daemonize.start() {
|
||||
Ok(_) => info!(LOGGER, "Grin server successfully started."),
|
||||
Err(e) => error!(LOGGER, "Error starting: {}", e),
|
||||
Ok(_) => info!("Grin server successfully started."),
|
||||
Err(e) => error!("Error starting: {}", e),
|
||||
}
|
||||
}
|
||||
("stop", _) => println!("TODO. Just 'kill $pid' for now. Maybe /tmp/grin.pid is $pid"),
|
||||
|
||||
+22
-24
@@ -35,7 +35,6 @@ use grin_wallet::{
|
||||
use keychain;
|
||||
use servers::start_webwallet_server;
|
||||
use util::file::get_first_line;
|
||||
use util::LOGGER;
|
||||
|
||||
pub fn _init_wallet_seed(wallet_config: WalletConfig) {
|
||||
if let Err(_) = WalletSeed::from_file(&wallet_config) {
|
||||
@@ -73,7 +72,7 @@ pub fn instantiate_wallet(
|
||||
println!("Error starting wallet: {}", e);
|
||||
process::exit(0);
|
||||
});
|
||||
info!(LOGGER, "Using LMDB Backend for wallet");
|
||||
info!("Using LMDB Backend for wallet");
|
||||
Box::new(db_wallet)
|
||||
}
|
||||
|
||||
@@ -107,7 +106,7 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) {
|
||||
// Generate the initial wallet seed if we are running "wallet init".
|
||||
if let ("init", Some(_)) = wallet_args.subcommand() {
|
||||
WalletSeed::init_file(&wallet_config).expect("Failed to init wallet seed file.");
|
||||
info!(LOGGER, "Wallet seed file created");
|
||||
info!("Wallet seed file created");
|
||||
let client =
|
||||
HTTPWalletClient::new(&wallet_config.check_node_api_http_addr, node_api_secret);
|
||||
let _: LMDBBackend<HTTPWalletClient, keychain::ExtKeychain> =
|
||||
@@ -117,7 +116,7 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) {
|
||||
e, wallet_config
|
||||
);
|
||||
});
|
||||
info!(LOGGER, "Wallet database backend created");
|
||||
info!("Wallet database backend created");
|
||||
// give logging thread a moment to catch up
|
||||
thread::sleep(Duration::from_millis(200));
|
||||
// we are done here with creating the wallet, so just return
|
||||
@@ -268,7 +267,6 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) {
|
||||
let slate = match result {
|
||||
Ok(s) => {
|
||||
info!(
|
||||
LOGGER,
|
||||
"Tx created: {} grin to {} (strategy '{}')",
|
||||
core::amount_to_hr_string(amount, false),
|
||||
dest,
|
||||
@@ -277,7 +275,7 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) {
|
||||
s
|
||||
}
|
||||
Err(e) => {
|
||||
error!(LOGGER, "Tx not created: {:?}", e);
|
||||
error!("Tx not created: {:?}", e);
|
||||
match e.kind() {
|
||||
// user errors, don't backtrace
|
||||
libwallet::ErrorKind::NotEnoughFunds { .. } => {}
|
||||
@@ -285,7 +283,7 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) {
|
||||
libwallet::ErrorKind::FeeExceedsAmount { .. } => {}
|
||||
_ => {
|
||||
// otherwise give full dump
|
||||
error!(LOGGER, "Backtrace: {}", e.backtrace().unwrap());
|
||||
error!("Backtrace: {}", e.backtrace().unwrap());
|
||||
}
|
||||
};
|
||||
panic!();
|
||||
@@ -294,18 +292,18 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) {
|
||||
let result = api.post_tx(&slate, fluff);
|
||||
match result {
|
||||
Ok(_) => {
|
||||
info!(LOGGER, "Tx sent",);
|
||||
info!("Tx sent",);
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
error!(LOGGER, "Tx not sent: {:?}", e);
|
||||
error!("Tx not sent: {:?}", e);
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
error!(
|
||||
LOGGER,
|
||||
"HTTP Destination should start with http://: or https://: {}", dest
|
||||
"HTTP Destination should start with http://: or https://: {}",
|
||||
dest
|
||||
);
|
||||
panic!();
|
||||
}
|
||||
@@ -321,7 +319,7 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) {
|
||||
).expect("Send failed");
|
||||
Ok(())
|
||||
} else {
|
||||
error!(LOGGER, "unsupported payment method: {}", method);
|
||||
error!("unsupported payment method: {}", method);
|
||||
panic!();
|
||||
}
|
||||
}
|
||||
@@ -354,11 +352,11 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) {
|
||||
let result = api.post_tx(&slate, fluff);
|
||||
match result {
|
||||
Ok(_) => {
|
||||
info!(LOGGER, "Tx sent");
|
||||
info!("Tx sent");
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
error!(LOGGER, "Tx not sent: {:?}", e);
|
||||
error!("Tx not sent: {:?}", e);
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
@@ -439,7 +437,7 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) {
|
||||
("repost", Some(repost_args)) => {
|
||||
let tx_id: u32 = match repost_args.value_of("id") {
|
||||
None => {
|
||||
error!(LOGGER, "Transaction of a completed but unconfirmed transaction required (specify with --id=[id])");
|
||||
error!("Transaction of a completed but unconfirmed transaction required (specify with --id=[id])");
|
||||
panic!();
|
||||
}
|
||||
Some(tx) => match tx.parse() {
|
||||
@@ -456,11 +454,11 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) {
|
||||
let result = api.post_stored_tx(tx_id, fluff);
|
||||
match result {
|
||||
Ok(_) => {
|
||||
info!(LOGGER, "Reposted transaction at {}", tx_id);
|
||||
info!("Reposted transaction at {}", tx_id);
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
error!(LOGGER, "Transaction reposting failed: {}", e);
|
||||
error!("Transaction reposting failed: {}", e);
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
@@ -469,11 +467,11 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) {
|
||||
let result = api.dump_stored_tx(tx_id, true, f);
|
||||
match result {
|
||||
Ok(_) => {
|
||||
warn!(LOGGER, "Dumped transaction data for tx {} to {}", tx_id, f);
|
||||
warn!("Dumped transaction data for tx {} to {}", tx_id, f);
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
error!(LOGGER, "Transaction reposting failed: {}", e);
|
||||
error!("Transaction reposting failed: {}", e);
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
@@ -488,11 +486,11 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) {
|
||||
let result = api.cancel_tx(tx_id);
|
||||
match result {
|
||||
Ok(_) => {
|
||||
info!(LOGGER, "Transaction {} Cancelled", tx_id);
|
||||
info!("Transaction {} Cancelled", tx_id);
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
error!(LOGGER, "TX Cancellation failed: {}", e);
|
||||
error!("TX Cancellation failed: {}", e);
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
@@ -501,12 +499,12 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) {
|
||||
let result = api.restore();
|
||||
match result {
|
||||
Ok(_) => {
|
||||
info!(LOGGER, "Wallet restore complete",);
|
||||
info!("Wallet restore complete",);
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
error!(LOGGER, "Wallet restore failed: {:?}", e);
|
||||
error!(LOGGER, "Backtrace: {}", e.backtrace().unwrap());
|
||||
error!("Wallet restore failed: {:?}", e);
|
||||
error!("Backtrace: {}", e.backtrace().unwrap());
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user