summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-06-16 14:07:06 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-06-16 14:07:06 +0200
commit0b0d883a00751c946fab4c897bab01859c598a88 (patch)
treee725eed6c843bf42d88ca46751f4c03bd21fed3f
parent766c56a693e8b1bd4293459bb256abdc0515a0b5 (diff)
downloadmad-0b0d883a00751c946fab4c897bab01859c598a88.tar
mad-0b0d883a00751c946fab4c897bab01859c598a88.zip
Logger werden jetzt durch shared_ptr gespeichert
-rw-r--r--src/Core/LogManager.cpp12
-rw-r--r--src/Core/LogManager.h16
-rw-r--r--src/mad.cpp2
-rw-r--r--src/modules/FileLogger/FileLogger.cpp6
-rw-r--r--src/modules/FileLogger/FileLogger.h8
5 files changed, 22 insertions, 22 deletions
diff --git a/src/Core/LogManager.cpp b/src/Core/LogManager.cpp
index bf9767b..91149f9 100644
--- a/src/Core/LogManager.cpp
+++ b/src/Core/LogManager.cpp
@@ -56,7 +56,7 @@ bool LogManager::handleConfigEntry(const ConfigEntry &entry, bool handled) {
if(entry[0].getKey().matches("Logger")) {
if(entry[0][0].matches("Console")) {
if(entry[1].empty()) {
- registerLogger(static_cast<Logger*>(&consoleLogger));
+ registerLogger(boost::static_pointer_cast<Logger>(consoleLogger));
return true;
}
}
@@ -71,10 +71,10 @@ bool LogManager::handleConfigEntry(const ConfigEntry &entry, bool handled) {
void LogManager::configFinished() {
if(loggers.empty())
- registerLogger(static_cast<Logger*>(&consoleLogger));
+ registerLogger(boost::static_pointer_cast<Logger>(consoleLogger));
// TODO Debug
- consoleLogger.Logger::setLevel(LoggerBase::DEBUG);
+ consoleLogger->Logger::setLevel(LoggerBase::DEBUG);
queueLock.lock();
configured = true;
@@ -84,7 +84,7 @@ void LogManager::configFinished() {
void LogManager::log(MessageCategory category, MessageLevel level, time_t timestamp, const std::string &message) {
if(level == LoggerBase::CRITICAL)
- consoleLogger.logMessageDirect(category, level, timestamp, message);
+ consoleLogger->logMessageDirect(category, level, timestamp, message);
queueLock.lock();
Message m = {category, level, timestamp, message};
@@ -116,7 +116,7 @@ void LogManager::loggerThread() {
lock.unlock();
loggerLock.lock();
- for(std::set<Logger*>::iterator logger = loggers.begin(); logger != loggers.end(); ++logger) {
+ for(std::set<boost::shared_ptr<Logger> >::iterator logger = loggers.begin(); logger != loggers.end(); ++logger) {
if((*logger)->getLevel() >= message.level && (*logger)->isCategorySet(message.category))
(*logger)->logMessage(message.category, message.level, message.timestamp, message.message);
}
@@ -131,7 +131,7 @@ void LogManager::loggerThread() {
lock.unlock();
remoteLoggerLock.lock();
- for(std::set<RemoteLogger*>::iterator logger = remoteLoggers.begin(); logger != remoteLoggers.end(); ++logger) {
+ for(std::set<boost::shared_ptr<RemoteLogger> >::iterator logger = remoteLoggers.begin(); logger != remoteLoggers.end(); ++logger) {
if((*logger)->getLevel() >= message.level && (*logger)->isCategorySet(message.category))
(*logger)->logMessage(message.category, message.level, message.timestamp, message.message, message.source);
}
diff --git a/src/Core/LogManager.h b/src/Core/LogManager.h
index 6d75b82..8c8d091 100644
--- a/src/Core/LogManager.h
+++ b/src/Core/LogManager.h
@@ -78,10 +78,10 @@ class LogManager : public Configurable {
static LogManager logManager;
- ConsoleLogger consoleLogger;
+ boost::shared_ptr<ConsoleLogger> consoleLogger;
- std::set<Logger*> loggers;
- std::set<RemoteLogger*> remoteLoggers;
+ std::set<boost::shared_ptr<Logger> > loggers;
+ std::set<boost::shared_ptr<RemoteLogger> > remoteLoggers;
bool configured, running;
boost::mutex queueLock;
@@ -101,7 +101,7 @@ class LogManager : public Configurable {
queueCond.notify_one();
}
- LogManager() : configured(false), running(false) {}
+ LogManager() : consoleLogger(new ConsoleLogger), configured(false), running(false) {}
protected:
virtual bool handleConfigEntry(const ConfigEntry &entry, bool handled);
@@ -111,25 +111,25 @@ class LogManager : public Configurable {
void log(MessageCategory category, MessageLevel level, time_t timestamp, const std::string &message);
void log(MessageCategory category, MessageLevel level, time_t timestamp, const std::string &message, const std::string &source);
- void registerLogger(Logger *logger) {
+ void registerLogger(boost::shared_ptr<Logger> logger) {
loggerLock.lock();
loggers.insert(logger);
loggerLock.unlock();
}
- void unregisterLogger(Logger *logger) {
+ void unregisterLogger(boost::shared_ptr<Logger> logger) {
loggerLock.lock();
loggers.erase(logger);
loggerLock.unlock();
}
- void registerLogger(RemoteLogger *logger) {
+ void registerLogger(boost::shared_ptr<RemoteLogger> logger) {
remoteLoggerLock.lock();
remoteLoggers.insert(logger);
remoteLoggerLock.unlock();
}
- void unregisterLogger(RemoteLogger *logger) {
+ void unregisterLogger(boost::shared_ptr<RemoteLogger> logger) {
remoteLoggerLock.lock();
remoteLoggers.erase(logger);
remoteLoggerLock.unlock();
diff --git a/src/mad.cpp b/src/mad.cpp
index 107f240..b1dbb8f 100644
--- a/src/mad.cpp
+++ b/src/mad.cpp
@@ -57,7 +57,7 @@ int main() {
Common::RequestManager::get()->registerConnection(connection);
- Core::Logger *networkLogger = new Daemon::Backends::NetworkLogger(connection);
+ boost::shared_ptr<Core::Logger> networkLogger(new Daemon::Backends::NetworkLogger(connection));
Core::LogManager::get()->registerLogger(networkLogger);
diff --git a/src/modules/FileLogger/FileLogger.cpp b/src/modules/FileLogger/FileLogger.cpp
index a78ab36..bdae536 100644
--- a/src/modules/FileLogger/FileLogger.cpp
+++ b/src/modules/FileLogger/FileLogger.cpp
@@ -26,7 +26,7 @@ namespace Mad {
namespace Modules {
FileLogger::ConfigHelper FileLogger::configHelper;
-std::set<FileLogger*> FileLogger::loggers;
+std::set<boost::shared_ptr<FileLogger> > FileLogger::loggers;
bool FileLogger::ConfigHelper::handleConfigEntry(const Core::ConfigEntry &entry, bool handled) {
@@ -37,10 +37,10 @@ bool FileLogger::ConfigHelper::handleConfigEntry(const Core::ConfigEntry &entry,
if(entry[0][0].matches("File")) {
if(entry[1].empty()) {
if(!entry[0][1].empty()) {
- FileLogger *logger = new FileLogger(entry[0][1]);
+ boost::shared_ptr<FileLogger> logger(new FileLogger(entry[0][1]));
loggers.insert(logger);
- Core::LogManager::get()->registerLogger(static_cast<Logger*>(logger));
+ Core::LogManager::get()->registerLogger(boost::static_pointer_cast<Logger>(logger));
}
else {
Logger::logf(Logger::WARNING, "FileLogger: no filename given.");
diff --git a/src/modules/FileLogger/FileLogger.h b/src/modules/FileLogger/FileLogger.h
index 04e2126..9b0f8e2 100644
--- a/src/modules/FileLogger/FileLogger.h
+++ b/src/modules/FileLogger/FileLogger.h
@@ -29,7 +29,7 @@
namespace Mad {
namespace Modules {
-class FileLogger : private Core::Logger, private Core::RemoteLogger {
+class FileLogger : public Core::Logger, public Core::RemoteLogger {
private:
class ConfigHelper : public Core::Configurable {
protected:
@@ -40,7 +40,7 @@ class FileLogger : private Core::Logger, private Core::RemoteLogger {
};
static ConfigHelper configHelper;
- static std::set<FileLogger*> loggers;
+ static std::set<boost::shared_ptr<FileLogger> > loggers;
std::ofstream file;
@@ -63,8 +63,8 @@ class FileLogger : private Core::Logger, private Core::RemoteLogger {
static void unregisterConfigHelper() {
Core::ConfigManager::get()->unregisterConfigurable(&configHelper);
- for(std::set<FileLogger*>::iterator logger = loggers.begin(); logger != loggers.end(); ++logger) {
- delete *logger;
+ for(std::set<boost::shared_ptr<FileLogger> >::iterator logger = loggers.begin(); logger != loggers.end(); ++logger) {
+ Core::LogManager::get()->unregisterLogger(boost::static_pointer_cast<Logger>(*logger));
}
loggers.clear();