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
+7 -8
View File
@@ -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
View File
@@ -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)
}
}
+6 -8
View File
@@ -24,7 +24,7 @@ extern crate daemonize;
extern crate serde;
extern crate serde_json;
#[macro_use]
extern crate slog;
extern crate log;
extern crate term;
extern crate grin_api as api;
@@ -45,7 +45,7 @@ use clap::{App, Arg, SubCommand};
use config::config::{SERVER_CONFIG_FILE_NAME, WALLET_CONFIG_FILE_NAME};
use core::global;
use util::{init_logger, LOGGER};
use util::init_logger;
// include build information
pub mod built_info {
@@ -73,9 +73,9 @@ pub fn info_strings() -> (String, String, String) {
fn log_build_info() {
let (basic_info, detailed_info, deps) = info_strings();
info!(LOGGER, "{}", basic_info);
debug!(LOGGER, "{}", detailed_info);
trace!(LOGGER, "{}", deps);
info!("{}", basic_info);
debug!("{}", detailed_info);
trace!("{}", deps);
}
fn main() {
@@ -378,7 +378,6 @@ fn main() {
l.tui_running = Some(false);
init_logger(Some(l));
warn!(
LOGGER,
"Using wallet configuration file at {}",
w.config_file_path.as_ref().unwrap().to_str().unwrap()
);
@@ -399,12 +398,11 @@ fn main() {
global::set_mining_mode(s.members.as_mut().unwrap().server.clone().chain_type);
if let Some(file_path) = &s.config_file_path {
info!(
LOGGER,
"Using configuration file at {}",
file_path.to_str().unwrap()
);
} else {
info!(LOGGER, "Node configuration file not found, using default");
info!("Node configuration file not found, using default");
}
node_config = Some(s);
}
+1 -2
View File
@@ -37,7 +37,6 @@ use servers::Server;
use tui::constants::ROOT_STACK;
use tui::types::{TUIStatusListener, UIMessage};
use tui::{menu, mining, peers, status, version};
use util::LOGGER;
use built_info;
@@ -172,7 +171,7 @@ impl Controller {
let mut next_stat_update = Utc::now().timestamp() + stat_update_interval;
while self.ui.step() {
if !running.load(Ordering::SeqCst) {
warn!(LOGGER, "Received SIGINT (Ctrl+C).");
warn!("Received SIGINT (Ctrl+C).");
server.stop();
self.ui.stop();
}