diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2018-07-09 14:11:07 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2018-07-09 14:11:07 +0200 |
commit | 9033aee6c281674e5d3d64e2f07bd8f7e7bbe694 (patch) | |
tree | a8748b55127d6be88e4b71b1dddf5985daac6a94 /src/main.cpp | |
parent | b84c8622d092fd773888eed89f1dbffb2c3a57f7 (diff) | |
parent | cb4fdfae7c68f6f4eef5893769f4b885bcb48186 (diff) |
Merge branch 'feature/upstream' into develop
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(); |