Add log rotation (#6564)

* Use flexi_logger; Add log rotation

* Add default rotation; Add FlexiLogger error

* Fix compilation error

* Remove logging to stdout if it's not a tty

* Fix formatting

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Remove needless debug statement

* Default to unlimited size for log rotation

* Add more comments about log-age option

* Remove unused variable

* Fix typo in comment

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
pscott
2020-07-08 12:11:09 +02:00
committed by GitHub
parent 62f306d972
commit 6eb2eb81c5
8 changed files with 324 additions and 84 deletions
+11 -2
View File
@@ -21,9 +21,10 @@
use crate::arg_enums::Database;
use crate::error::Result;
use crate::{
init_logger, DatabaseParams, ImportParams, KeystoreParams, NetworkParams, NodeKeyParams,
DatabaseParams, ImportParams, KeystoreParams, NetworkParams, NodeKeyParams,
OffchainWorkerParams, PruningParams, SharedParams, SubstrateCli,
};
use crate::logger::{LogRotationOpt, init_logger};
use names::{Generator, Name};
use sc_client_api::execution_extensions::ExecutionStrategies;
use sc_service::config::{
@@ -488,6 +489,13 @@ pub trait CliConfiguration: Sized {
Ok(self.shared_params().log_filters().join(","))
}
/// Get the log directory for logging.
///
/// By default this is retrieved from `SharedParams`.
fn log_rotation_opt(&self) -> Result<&LogRotationOpt> {
Ok(self.shared_params().log_rotation_opt())
}
/// Initialize substrate. This must be done only once.
///
/// This method:
@@ -497,11 +505,12 @@ pub trait CliConfiguration: Sized {
/// 3. Initialize the logger
fn init<C: SubstrateCli>(&self) -> Result<()> {
let logger_pattern = self.log_filters()?;
let log_rotation_opt = self.log_rotation_opt()?;
sp_panic_handler::set(&C::support_url(), &C::impl_version());
fdlimit::raise_fd_limit();
init_logger(&logger_pattern);
init_logger(&logger_pattern, log_rotation_opt)?;
Ok(())
}