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