From 8111b77e95b083137faf888aeb5892073adf7ab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Wed, 27 Jun 2018 16:59:37 +0200 Subject: New upstream version 2.0.0 --- src/bitz/config.cpp | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) (limited to 'src/bitz/config.cpp') diff --git a/src/bitz/config.cpp b/src/bitz/config.cpp index aaa247f..f5ef810 100644 --- a/src/bitz/config.cpp +++ b/src/bitz/config.cpp @@ -18,9 +18,7 @@ */ #include "config.h" -#include "logger.h" -#include #include @@ -32,7 +30,6 @@ namespace bitz { _config.port = 1344; _config.pid_file = "/dev/null"; _config.log_file = "/dev/null"; - _config.log_category = "bitz"; _config.req_handlers_count = 0; _config.req_handlers = NULL; @@ -44,6 +41,9 @@ namespace bitz { // defaults _lconfig = NULL; + // logger + _logger = spdlog::get( "bitz-server" ); + } Config::~Config() { @@ -72,12 +72,10 @@ namespace bitz { try { config->readFile( config_file.c_str() ); } catch ( const libconfig::FileIOException &ex ) { - std::cerr << "[config] failed to read config file: " << config_file - << ", exception: " << ex.what() << std::endl; + _logger->error( "[config] failed to read config file: {}, exception: {}", config_file, ex.what() ); exit( EXIT_FAILURE ); } catch ( const libconfig::ParseException &pex ) { - std::cerr << "[config] parse error at " << pex.getFile() - << ":" << pex.getLine() << " - " << pex.getError() << std::endl; + _logger->error( "[config] parse error at {}:{} - {}", pex.getFile(), pex.getLine(), pex.getError() ); exit( EXIT_FAILURE ); } @@ -87,7 +85,6 @@ namespace bitz { config->lookupValue( "port", _config.port ); config->lookupValue( "pid_file", _config.pid_file ); config->lookupValue( "log_file", _config.log_file ); - config->lookupValue( "log_category", _config.log_category ); config->lookupValue( "max_workers", _config.max_workers ); config->lookupValue( "max_worker_requests", _config.max_worker_requests ); @@ -95,8 +92,7 @@ namespace bitz { config->lookupValue( "comm_timeout", _config.comm_timeout ); } catch ( const libconfig::SettingNotFoundException &e ) { - std::cerr << "[config] failed to load core configs, " - << e.getPath() << " : " << e.what() << std::endl; + _logger->error( "[config] failed to load core configs, {} : {}", e.getPath(), e.what() ); } // cache configs @@ -125,12 +121,11 @@ namespace bitz { libconfig::Setting &setting = _lconfig->lookup( std::string( "modules." ).append( module ) ); setting.lookupValue( config, config_value ); } catch ( const libconfig::SettingNotFoundException &e ) { - // TODO: log errors ?? - std::cerr << "[config] " << e.getPath() << " : " << e.what() << std::endl; + _logger->error( "[config] {} : {}", e.getPath(), e.what() ); } } else { - std::cout << "[config] 'modules' configs not found" << std::endl; + _logger->info( "[config] 'modules' configs not found" ); } return config_value; @@ -143,16 +138,14 @@ namespace bitz { int i, j; std::string s; - std::cout << "[config] looking for req_handlers... "; + _logger->trace( "[config] looking for req_handlers" ); if ( _lconfig->exists( "req_handlers" ) ) { - std::cout << "found "; - libconfig::Setting &req_handlers = _lconfig->lookup( "req_handlers" ); _config.req_handlers_count = req_handlers.getLength(); _config.req_handlers = new req_handlers_config_t[_config.req_handlers_count]; - std::cout << "(" << _config.req_handlers_count << ")" << std::endl; + _logger->debug( "[config] found {} request handlers", _config.req_handlers_count ); try { @@ -162,29 +155,28 @@ namespace bitz { _config.req_handlers[i].class_name = (const char *) req_handlers[i]["class"]; // read request handler modules config - std::cout << "[config] looking for " << _config.req_handlers[i].name << " modules... "; + _logger->debug( "[config] looking for {} modules", _config.req_handlers[i].name ); if ( req_handlers[i].exists( "modules" ) ) { - std::cout << "found "; _config.req_handlers[i].modules_count = req_handlers[i]["modules"].getLength(); _config.req_handlers[i].modules = new modules_config_t[_config.req_handlers[i].modules_count]; - std::cout << "(" << _config.req_handlers[i].modules_count << ")" << std::endl; + _logger->debug( "[config] found {} modules for {}", _config.req_handlers[i].modules_count, _config.req_handlers[i].name ); for ( j = 0; j < _config.req_handlers[i].modules_count; j++ ) { _config.req_handlers[i].modules[j].name = (const char *) req_handlers[i]["modules"][j]["name"]; _config.req_handlers[i].modules[j].module = (const char *) req_handlers[i]["modules"][j]["module"]; } } else { - std::cout << "not found" << std::endl; + _logger->info( "[config] no modules found for {}", _config.req_handlers[i].name ); } } } catch ( const libconfig::SettingNotFoundException &ex ) { - std::cerr << "[config] Error: " << ex.getPath() << ex.what() << std::endl; + _logger->error( "[config] {} : {}", ex.getPath(), ex.what() ); } } else { - std::cout << "not found" << std::endl; + _logger->info( "[config] no request handlers found" ); } } -- cgit v1.2.3