22 #include <boost/filesystem.hpp> 24 #include <boost/log/utility/setup/file.hpp> 25 #include <boost/log/utility/setup/console.hpp> 26 #include <boost/log/utility/setup/common_attributes.hpp> 27 #include <boost/log/utility/setup/formatter_parser.hpp> 32 using boost::make_shared;
53 #ifdef ALACARTE_NO_BACKBONE 63 std::string info = boost::current_exception_diagnostic_information();
65 BOOST_LOG_TRIVIAL(fatal) <<
"Boost diagnostic:\n" << info;
81 shared_ptr<Configuration>
config;
86 }
catch(boost::program_options::error& e)
88 std::cout <<
"Error: " << e.what() << std::endl;
105 config->printConfigToLog();
110 const std::vector<string> &dirs = config->getSearchDirectories();
111 LOG_SEV(app_log, error) <<
"The given config file was not found. Searched for:";
113 std::for_each(begin(dirs), end(dirs), [&](
const string &dir)
133 keywords::file_name = config->get<
string>(
opt::logfile),
134 keywords::rotation_size = 10 * 1024 * 1024,
135 keywords::time_based_rotation = logging::sinks::file::rotation_at_time_point(0, 0, 0),
136 keywords::format =
"<%TimeStamp%>: [%Channel%] %Severity%: %Message%" 140 keywords::format =
"[%Channel%] %Severity%: %Message%" 143 logging::add_common_attributes();
145 logging::core::get()->set_filter
147 logging::trivial::severity >= logging::trivial::info
155 if (config->has(key)) {
156 boost::filesystem::path file = config->get<
string>(key);
157 bool exists = boost::filesystem::exists(file);
159 LOG_SEV(app_log, error) << key <<
" = \"" << file.string() <<
"\" does not exist.";
163 LOG_SEV(app_log, error) << key <<
" is not set.";
boost::program_options::positional_options_description pos_desc
virtual bool startupDiagnostic(const shared_ptr< Configuration > &config)=0
virtual void onRun(const shared_ptr< Configuration > &config)=0
shared_ptr< logging::sinks::synchronous_sink< logging::sinks::basic_text_ostream_backend< char > > > consoleLogger
Application()
Inits the new Application.
shared_ptr< logging::sinks::synchronous_sink< logging::sinks::text_file_backend > > fileLogger
#define LOG_SEV(log, lvl)
virtual void customInitLog(const shared_ptr< Configuration > &config)
bool diagnosticCheckFile(const shared_ptr< Configuration > &config, const string &key)
boost::program_options::options_description config_desc
void appRun(int argc, char **argv)
Creates the Configuration and runs the application.
#define DEFAULT_CONFIG_NAME
boost::program_options::options_description cmd_desc
static const char * config
Option to get the configuration filename (type: string)
static const char * help
Use Configuration::has to check weather the user wanted help.
int start(int argc, char **argv)
Starts the aplication with or without Exceptionhandling.
void initLog(const shared_ptr< Configuration > &config)
Inits the logfile.
static const char * logfile
Option to get the filename of the log (type: string)