Skip to content

Commit

Permalink
Merge pull request #826 from koinos/normalize-logs
Browse files Browse the repository at this point in the history
Upgrade log library to v2.0.0
  • Loading branch information
mvandeberg authored Oct 3, 2023
2 parents e378678 + 71baed3 commit 7014100
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ HunterGate(
LOCAL
)

project(koinos_chain VERSION 1.1.0 LANGUAGES CXX C)
project(koinos_chain VERSION 1.2.0 LANGUAGES CXX C)
add_compile_definitions(KOINOS_MAJOR_VERSION=${PROJECT_VERSION_MAJOR})
add_compile_definitions(KOINOS_MINOR_VERSION=${PROJECT_VERSION_MINOR})
add_compile_definitions(KOINOS_PATCH_VERSION=${PROJECT_VERSION_PATCH})
Expand Down
28 changes: 24 additions & 4 deletions programs/koinos_chain/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
#define AMQP_DEFAULT "amqp://guest:guest@localhost:5672/"
#define LOG_LEVEL_OPTION "log-level"
#define LOG_LEVEL_DEFAULT "info"
#define LOG_DIR_OPTION "log-dir"
#define LOG_DIR_DEFAULT ""
#define LOG_COLOR_OPTION "log-color"
#define LOG_COLOR_DEFAULT true
#define LOG_DATETIME_OPTION "log-datetime"
#define LOG_DATETIME_DEFAULT true
#define INSTANCE_ID_OPTION "instance-id"
#define STATEDIR_OPTION "statedir"
#define JOBS_OPTION "jobs"
Expand All @@ -72,11 +78,11 @@ void attach_request_handler( chain::controller& controller, mq::request_handler&

int main( int argc, char** argv )
{
std::string amqp_url, log_level, instance_id, fork_algorithm_option;
std::string amqp_url, log_level, log_dir, instance_id, fork_algorithm_option;
std::filesystem::path statedir, genesis_data_file;
uint64_t jobs, read_compute_limit;
chain::genesis_data genesis_data;
bool reset;
bool reset, log_color, log_datetime;
chain::fork_resolution_algorithm fork_algorithm;

try
Expand All @@ -96,7 +102,10 @@ int main( int argc, char** argv )
(STATEDIR_OPTION , program_options::value< std::string >(),
"The location of the blockchain state files (absolute path or relative to basedir/chain)")
(RESET_OPTION , program_options::value< bool >(), "Reset the database")
(FORK_ALGORITHM_OPTION ",f", program_options::value< std::string >(), "The fork resolution algorithm to use. Can be 'fifo', 'pob', or 'block-time'. (Default: 'fifo')");
(FORK_ALGORITHM_OPTION ",f", program_options::value< std::string >(), "The fork resolution algorithm to use. Can be 'fifo', 'pob', or 'block-time'. (Default: 'fifo')")
(LOG_DIR_OPTION , program_options::value< std::string >(), "The logging directory")
(LOG_COLOR_OPTION , program_options::value< bool >(), "Log color toggle")
(LOG_DATETIME_OPTION , program_options::value< bool >(), "Log datetime on console toggle");

program_options::variables_map args;
program_options::store( program_options::parse_command_line( argc, argv, options ), args );
Expand Down Expand Up @@ -138,6 +147,9 @@ int main( int argc, char** argv )

amqp_url = util::get_option< std::string >( AMQP_OPTION, AMQP_DEFAULT, args, chain_config, global_config );
log_level = util::get_option< std::string >( LOG_LEVEL_OPTION, LOG_LEVEL_DEFAULT, args, chain_config, global_config );
log_dir = util::get_option< std::string >( LOG_DIR_OPTION, LOG_DIR_DEFAULT, args, chain_config, global_config );
log_color = util::get_option< bool >( LOG_COLOR_OPTION, LOG_COLOR_DEFAULT, args, chain_config, global_config );
log_datetime = util::get_option< bool >( LOG_DATETIME_OPTION, LOG_DATETIME_DEFAULT, args, chain_config, global_config );
instance_id = util::get_option< std::string >( INSTANCE_ID_OPTION, util::random_alphanumeric( 5 ), args, chain_config, global_config );
statedir = std::filesystem::path( util::get_option< std::string >( STATEDIR_OPTION, STATEDIR_DEFAULT, args, chain_config, global_config ) );
genesis_data_file = std::filesystem::path( util::get_option< std::string >( GENESIS_DATA_FILE_OPTION, GENESIS_DATA_FILE_DEFAULT, args, chain_config, global_config ) );
Expand All @@ -146,7 +158,15 @@ int main( int argc, char** argv )
read_compute_limit = util::get_option< uint64_t >( READ_COMPUTE_BANDWITH_LIMIT_OPTION, READ_COMPUTE_BANDWITH_LIMIT_DEFAULT, args, chain_config, global_config );
fork_algorithm_option = util::get_option< std::string >( FORK_ALGORITHM_OPTION, FORK_ALGORITHM_DEFAULT, args, chain_config, global_config );

koinos::initialize_logging( util::service::chain, instance_id, log_level, basedir / util::service::chain / "logs" );
std::optional< std::filesystem::path > logdir_path;
if ( !log_dir.empty() )
{
logdir_path = std::make_optional< std::filesystem::path >( log_dir );
if ( logdir_path->is_relative() )
logdir_path = basedir / util::service::chain / *logdir_path;
}

koinos::initialize_logging( util::service::chain, instance_id, log_level, logdir_path, log_color, log_datetime );

LOG(info) << version_string();

Expand Down

0 comments on commit 7014100

Please sign in to comment.