diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2018-07-11 07:33:08 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2018-07-11 07:33:08 +0200 |
commit | 621f4acf1406e51eaf5d9429c46625e6f5fde98e (patch) | |
tree | 0fe1fd92a0502602f54b2bf12a8c247ef575d00f /src/main.cpp | |
parent | 25d4e8d5ee396a852568b7ae1c15971a9da409db (diff) | |
parent | 5aa4b715375b173e9c24363f977883786b05cd6d (diff) |
Merge branch 'release/debian/2.0.0-1'debian/2.0.0-1
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/main.cpp b/src/main.cpp index 7570e3a..c65ccc4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,8 +22,8 @@ #include <config.h> #include "bitz-server.h" #include "bitz/config.h" -#include "bitz/logger.h" #include "bitz/util.h" +#include "spdlog/spdlog.h" int main( int argc, char **argv ) { @@ -34,6 +34,12 @@ int main( int argc, char **argv ) { // read command line options bitz::server::options_t opt = bitz::server::read_options( argc, argv ); + // logger + auto logger = spdlog::stdout_color_st( "bitz-server" ); + if ( opt.debug_flag == 1 ) { + spdlog::set_level( spdlog::level::debug ); + } + // initialise configurations bitz::Config &server_config = bitz::Config::instance(); @@ -48,28 +54,39 @@ int main( int argc, char **argv ) { // create directories if ( ( opt.debug_flag != 1 ) && (! bitz::util::mkdirp( bitz::util::dirpath( config.pid_file ) ) ) ) { - std::cerr << "[core] failed to create run dir" << std::endl; + logger->critical( "[core] failed to create run dir" ); exit( EXIT_FAILURE ); } if (! bitz::util::mkdirp( bitz::util::dirpath( config.log_file ) ) ) { - std::cerr << "[core] failed to create log dir" << std::endl; + logger->critical( "[core] failed to create log dir" ); exit( EXIT_FAILURE ); } // daemonize if ( opt.debug_flag != 1 ) { + + // close stdout logger + spdlog::drop( "bitz-server" ); + + // daemonize bitz::server::daemonize( bitz::util::dirpath( config.pid_file ).c_str(), config.pid_file.c_str() ); + + // open a file logger + logger = spdlog::rotating_logger_mt( "bitz-server", config.log_file, ( 1048576 * 1024 ), 7 ); + + } else { + logger->info( "{} initialised", PACKAGE_STRING ); } - // initialise the logger - bitz::Logger &logger = bitz::Logger::instance( config.log_file, config.log_category ); - logger.info( std::string( PACKAGE_STRING ) + " initialised" ); // start the server bitz::server::start( config.port, config.max_workers, config.max_worker_requests, config.comm_timeout ); + // flush logs + logger->flush(); + // run the server bitz::server::run(); |