Ver Fonte

Add Application Start/Stop Logging

JDierkse há 5 anos atrás
pai
commit
e0ea192dda
1 ficheiros alterados com 21 adições e 3 exclusões
  1. 21 3
      Application/AlarmServer.cc

+ 21 - 3
Application/AlarmServer.cc

@@ -1,4 +1,5 @@
 #include "MailServer/Server.h"
+#include <Logging.h>
 #include <asio.hpp>
 #include <sys/types.h>
 #include <fcntl.h>
@@ -10,6 +11,9 @@ int main(int argc, char* argv[])
 {
 	try
 	{
+		Logging::OpenLog();
+		Logging::SetLogMask(Logging::Severity::Debug);
+
 		/* error checking elided for brevity */
 		int fd = ::open("/dev/null", O_WRONLY);
 		::dup2(fd, 2);
@@ -36,14 +40,28 @@ int main(int argc, char* argv[])
 			return 1;
 		}
 
-		asio::io_service io_service;
+		Logging::Log(Logging::Severity::Info, "Starting AlarmServer");
 
+		asio::io_service io_service;
 		MailServer::Server s(io_service, port, path, url);
-
 		io_service.run();
+
+		Logging::Log(Logging::Severity::Info, "Stopping AlarmServer...");
+
+		Logging::CloseLog();
 	}
 	catch (std::exception& e)
 	{
-		std::cerr << "Exception: " << e.what() << std::endl;
+		std::stringstream ss;
+		ss << "ERROR: " << e.what() << std::endl;
+
+		std::cerr << ss.str() << std::endl;
+		Logging::Log(Logging::Severity::Error, ss.str());
+
+		Logging::CloseLog();
+
+		return -1;
 	}
+
+	return 0;
 }