From 7d26bc794708b1421e28330562ebe5abe21c2cad Mon Sep 17 00:00:00 2001 From: Phillip Mienk Date: Fri, 21 Oct 2016 12:21:50 -0700 Subject: [PATCH 1/2] Add configuration based logging options for log rotation. --- console/executor.cpp | 26 ++++++++++++++++++++------ src/parser.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/console/executor.cpp b/console/executor.cpp index d5a0da2b..865da0eb 100644 --- a/console/executor.cpp +++ b/console/executor.cpp @@ -41,6 +41,8 @@ using namespace bc::database; using namespace bc::network; using namespace std::placeholders; +namespace keywords = boost::log::keywords; + static const auto application_name = "bs"; static constexpr int initialize_stop = 0; static constexpr int directory_exists = 0; @@ -53,16 +55,28 @@ executor::executor(parser& metadata, std::istream& input, std::ostream& output, std::ostream& error) : metadata_(metadata), output_(output), error_(error) { - const auto debug_file = metadata_.configured.network.debug_file.string(); - const auto error_file = metadata_.configured.network.error_file.string(); - - auto debug_log = boost::make_shared(debug_file, mode); - auto error_log = boost::make_shared(error_file, mode); + const log::file_sink_configuration debug_file = { + metadata_.configured.network.debug_file.string(), + metadata_.configured.network.logs_path.string(), + metadata_.configured.network.log_rotation_size, + metadata_.configured.network.log_max_files, + metadata_.configured.network.log_max_files_size, + metadata_.configured.network.log_min_free_space + }; + + const log::file_sink_configuration error_file = { + metadata_.configured.network.error_file.string(), + metadata_.configured.network.logs_path.string(), + metadata_.configured.network.log_rotation_size, + metadata_.configured.network.log_max_files, + metadata_.configured.network.log_max_files_size, + metadata_.configured.network.log_min_free_space + }; log::stream console_out(&output_, null_deleter()); log::stream console_err(&error_, null_deleter()); - log::initialize(debug_log, error_log, console_out, console_err); + log::initialize(debug_file, error_file, console_out, console_err); handle_stop(initialize_stop); } diff --git a/src/parser.cpp b/src/parser.cpp index a9450ce4..d42a7a05 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -234,6 +234,31 @@ options_metadata parser::load_settings() value(&configured.network.error_file), "The error log file path, defaults to 'error.log'." ) + ( + "network.logs_path", + value(&configured.network.logs_path), + "The path to log files not including name, defaults to 'logs'." + ) + ( + "network.log_rotation_size", + value(&configured.network.log_rotation_size), + "The size at which logs are to be rotated, defaults to 'maximum'." + ) +// ( +// "network.log_max_files", +// value(&configured.network.log_max_files), +// "The maximum number of logs to persist, defaults to 'maximum'." +// ) + ( + "network.log_max_files_size", + value(&configured.network.log_max_files_size), + "The cumulative maximum size in bytes of logs, defaults to 'maximum'." + ) + ( + "network.log_min_free_space", + value(&configured.network.log_min_free_space), + "The minimum free space in bytes to be maintained in the logs_path, defaults to '0'." + ) ( "network.self", value(&configured.network.self), From bf520ddf2fcc58300c39215b02ea1e89a2b36f6f Mon Sep 17 00:00:00 2001 From: Phillip Mienk Date: Fri, 21 Oct 2016 13:19:31 -0700 Subject: [PATCH 2/2] Comment out currently unused property. --- console/executor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/console/executor.cpp b/console/executor.cpp index 865da0eb..78404901 100644 --- a/console/executor.cpp +++ b/console/executor.cpp @@ -59,7 +59,7 @@ executor::executor(parser& metadata, std::istream& input, metadata_.configured.network.debug_file.string(), metadata_.configured.network.logs_path.string(), metadata_.configured.network.log_rotation_size, - metadata_.configured.network.log_max_files, +// metadata_.configured.network.log_max_files, metadata_.configured.network.log_max_files_size, metadata_.configured.network.log_min_free_space }; @@ -68,7 +68,7 @@ executor::executor(parser& metadata, std::istream& input, metadata_.configured.network.error_file.string(), metadata_.configured.network.logs_path.string(), metadata_.configured.network.log_rotation_size, - metadata_.configured.network.log_max_files, +// metadata_.configured.network.log_max_files, metadata_.configured.network.log_max_files_size, metadata_.configured.network.log_min_free_space };