[dss-commits] digitalSTROM Server branch, master, updated. e3ee6dcd6a6bc9e5d2cde6275ce4ac118cf8fec2
git version control
dss-commits at forum.digitalstrom.org
Tue Jan 5 16:35:03 CET 2010
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "digitalSTROM Server".
The branch, master has been updated
via e3ee6dcd6a6bc9e5d2cde6275ce4ac118cf8fec2 (commit)
from 356f356bc70e84f152bd8b8126a51acae9a1727a (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit e3ee6dcd6a6bc9e5d2cde6275ce4ac118cf8fec2
Author: Patrick Stählin <pstaehlin at futurelab.ch>
Date: Tue Jan 5 16:29:50 2010 +0100
Feature to register log handlers added
Patch by Sebastian Kohler, aizo ag
-----------------------------------------------------------------------
Changes:
diff --git a/core/logger.cpp b/core/logger.cpp
index 7ea2520..7ba39f0 100644
--- a/core/logger.cpp
+++ b/core/logger.cpp
@@ -22,6 +22,7 @@
#include "logger.h"
#include "base.h"
+#include "foreach.h"
#include <cassert>
#include <iostream>
@@ -29,6 +30,8 @@
namespace dss {
Logger* Logger::m_Instance = NULL;
+ Mutex Logger::m_handlerListMutex = Mutex();
+ std::list<LogHandler *> Logger::m_handlerList = std::list<LogHandler *>();
template <class t>
t SeverityToString(const aLogSeverity _severity);
@@ -102,14 +105,26 @@ namespace dss {
void Logger::log(const std::string& _message, const aLogSeverity _severity) {
time_t now = time( NULL );
struct tm t;
+ std::string logMessage;
#ifdef WIN32
localtime_s( &t, &now );
#else
localtime_r( &now, &t );
#endif
- m_logTarget->outputStream() << "[" << dateToISOString<std::string>(&t) << "]"
- << SeverityToString<const std::string>(_severity)
- << " " << _message << std::endl;
+
+ logMessage = "[" + dateToISOString<std::string>(&t) + "]"
+ + SeverityToString<const std::string>(_severity)
+ + " " + _message + "\n";
+
+ m_logTarget->outputStream() << logMessage; // only for backward compatibility
+
+/*
+ m_handlerListMutex.lock();
+ foreach(LogHandler *h,m_handlerList) {
+ h->handle(logMessage);
+ }
+ m_handlerListMutex.unlock();
+*/
} // log
void Logger::log(const char* _message, const aLogSeverity _severity) {
@@ -137,4 +152,19 @@ namespace dss {
return m_logTarget->open();
}
+
+ void Logger::registerHandler(LogHandler& _logHandler) {
+ m_handlerListMutex.lock();
+ m_handlerList.push_back(&_logHandler);
+ m_handlerListMutex.unlock();
+ } //registerHandler
+
+ void Logger::deregisterHandler(LogHandler& _logHandler) {
+ m_handlerListMutex.lock();
+ std::list<LogHandler *>::iterator it = find(m_handlerList.begin(), m_handlerList.end(), &_logHandler);
+ if (it != m_handlerList.end()) {
+ m_handlerList.erase(it);
+ }
+ m_handlerListMutex.unlock();
+ } // deregisterHandler
}
diff --git a/core/logger.h b/core/logger.h
index c610b12..fcebf3f 100644
--- a/core/logger.h
+++ b/core/logger.h
@@ -28,6 +28,8 @@
#include <fstream>
#include <iostream>
#include <boost/shared_ptr.hpp>
+#include <list>
+#include "mutex.h"
typedef enum {
lsDebug = 0,
@@ -41,6 +43,7 @@ namespace dss {
class LogChannel;
class LogTarget;
+class LogHandler;
class Logger {
public:
@@ -55,6 +58,9 @@ class LogTarget;
bool setLogTarget(boost::shared_ptr<LogTarget>& _logTarget);
bool reopenLogTarget();
+ void registerHandler(LogHandler& _logHandler);
+ void deregisterHandler(LogHandler& _logHandler);
+
private:
Logger();
@@ -62,6 +68,8 @@ class LogTarget;
boost::shared_ptr<LogTarget> m_logTarget;
+ static Mutex m_handlerListMutex;
+ static std::list<LogHandler *> m_handlerList;
}; // Logger
class LogChannel {
@@ -126,6 +134,52 @@ private:
std::ofstream m_fileOutputStream;
}; // FileLogTarget
+class LogHandler {
+public:
+ virtual void handle(const std::string &_message) = 0;
+
+ virtual ~LogHandler() {};
+}; // LogHandler
+
+class CoutLogHandler : public LogHandler {
+public:
+ void handle(const std::string &_message) {
+ std::cout << _message;
+ }
+
+ ~CoutLogHandler() {}
+}; // CoutLogHandler
+
+class FileLogHandler : public LogHandler {
+public:
+ FileLogHandler(const std::string& _fileName) : m_fileName(_fileName) {};
+ ~FileLogHandler() {};
+
+ void handle(const std::string &_message) {
+ m_fileOutputStream << _message;
+ }
+
+ virtual bool open() {
+ m_fileOutputStream.open(m_fileName.c_str(), std::ios::out|std::ios::app);
+ m_fileOpen = true;
+ m_fileOutputStream << "-- File opened" << std::endl;
+ return m_fileOutputStream.good();
+ }
+
+ virtual void close() {
+ if(m_fileOpen) {
+ m_fileOutputStream << "-- File closed" << std::endl;
+ m_fileOutputStream.close();
+ m_fileOpen = false;
+ }
+ }
+
+private:
+ std::string m_fileName;
+ bool m_fileOpen;
+ std::ofstream m_fileOutputStream;
+}; // FileLogHandler
+
}
#endif
hooks/post-receive
--
digitalSTROM Server
More information about the dss-commits
mailing list