#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define PROJECT_VERSION "v0.3.0" namespace po = boost::program_options; namespace logging = boost::log; App app; void signal_handler(int s) { app.Shutdown(); } void InitLogging(bool verbose) { logging::add_console_log( std::clog, logging::keywords::format = (logging::expressions::stream << "[" << logging::expressions::format_date_time( "TimeStamp", "%Y-%m-%d %H:%M:%S") << "][" << logging::expressions::format_named_scope( "Scope", logging::keywords::format = "%c") << "]" << "[" << logging::trivial::severity << "] " << logging::expressions::smessage)); logging::add_common_attributes(); logging::core::get()->add_global_attribute( "Scope", logging::attributes::named_scope()); BOOST_LOG_FUNCTION(); if (!verbose) { logging::core::get()->set_filter(logging::trivial::severity >= logging::trivial::info); } else { BOOST_LOG_TRIVIAL(info) << "Verbose logging enabled"; } } int main(int argc, char **argv) { BOOST_LOG_FUNCTION() BOOST_LOG_TRIVIAL(info) << "Version: " << PROJECT_VERSION; signal(SIGINT, signal_handler); signal(SIGTERM, signal_handler); po::options_description desc("Allowed options"); desc.add_options()("help,h", "produce help message")( "setup,s", po::bool_switch(), "run initial setup")("verbose,v", po::bool_switch(), "print debug info"); po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); po::notify(vm); try { InitLogging(vm["verbose"].as()); if (vm.count("help")) { std::cout << desc << "\n"; return 0; } if (vm.count("setup") && vm["setup"].as()) { app.InitialSetup(); } else { app.Init(); app.NormalOperation(); } } catch (const std::exception &e) { std::cout << "An exception was caught: " << e.what() << std::endl; } app.Shutdown(); return 0; }