X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffmsapp.cpp;fp=src%2Ffmsapp.cpp;h=04562fc3afa06b798b95256108e71b0d38c59b8a;hb=3751f10f7127ae0905aa0b52dc6de1c782a38c99;hp=810bd5f3e9c07dc7c67fe7c091047c2400d150ce;hpb=76805933f794915a72b7f0a21b12af6654759f4f;p=fms.git diff --git a/src/fmsapp.cpp b/src/fmsapp.cpp index 810bd5f..04562fc 100644 --- a/src/fmsapp.cpp +++ b/src/fmsapp.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -43,7 +44,7 @@ public: } }; -FMSApp::FMSApp():m_displayhelp(false) +FMSApp::FMSApp():m_displayhelp(false),m_logtype("file") { } @@ -54,6 +55,7 @@ void FMSApp::defineOptions(Poco::Util::OptionSet &options) // add command line options here options.addOption(Poco::Util::Option("help","?","display help for command line arguments",false).repeatable(false).callback(Poco::Util::OptionCallback(this,&FMSApp::handleHelp))); + options.addOption(Poco::Util::Option("log","l","select type of log output (file|stdout|stderr)",false,"type",true).repeatable(false).callback(Poco::Util::OptionCallback(this,&FMSApp::handleLogOption))); } void FMSApp::displayHelp() @@ -72,6 +74,14 @@ void FMSApp::handleHelp(const std::string &name, const std::string &value) stopOptionsProcessing(); } +void FMSApp::handleLogOption(const std::string &name, const std::string &value) +{ + if(value=="file" || value=="stdout" || value=="stderr") + { + m_logtype=value; + } +} + void FMSApp::initialize(Poco::Util::Application &self) { ServerApplication::initialize(self); @@ -96,13 +106,30 @@ void FMSApp::initializeLogger() } Poco::AutoPtr formatter=new Poco::FormattingChannel(new Poco::PatternFormatter("%Y-%m-%d %H:%M:%S | %p | %t")); - Poco::AutoPtr fc=new Poco::FileChannel("fms.log"); - fc->setProperty("rotation","daily"); // rotate log file daily - fc->setProperty("times","utc"); // utc date/times for log entries - fc->setProperty("archive","timestamp"); // add timestamp to old logs - fc->setProperty("purgeCount","30"); // purge old logs after 30 logs have accumulated - fc->setProperty("compress","true"); // gz compress old log files - formatter->setChannel(fc); + + if(m_logtype=="file") + { + Poco::AutoPtr fc=new Poco::FileChannel("fms.log"); + fc->setProperty("rotation","daily"); // rotate log file daily + fc->setProperty("times","utc"); // utc date/times for log entries + fc->setProperty("archive","timestamp"); // add timestamp to old logs + fc->setProperty("purgeCount","30"); // purge old logs after 30 logs have accumulated + fc->setProperty("compress","true"); // gz compress old log files + formatter->setChannel(fc); + } + else + { + if(m_logtype=="stdout") + { + Poco::AutoPtr cc=new Poco::ConsoleChannel(std::cout); + formatter->setChannel(cc); + } + else + { + Poco::AutoPtr cc=new Poco::ConsoleChannel(std::cerr); + formatter->setChannel(cc); + } + } setLogger(Poco::Logger::create("logfile",formatter,initiallevel)); } @@ -110,12 +137,22 @@ void FMSApp::initializeLogger() int FMSApp::main(const std::vector &args) { + // running as a daemon would reset the working directory to / before calling main + // so we need to set the working directory again + // set working directory to program directory + int rval=chdir(config().getString("application.dir").c_str()); + if(m_displayhelp==false) { logger().information("FMS startup v"FMS_VERSION); StartThreads(); + if(isInteractive()==true) + { + std::cout << "FMS has been started." << std::endl << std::endl; + } + waitForTerminationRequest(); m_threads.Cancel();