From: Christian P. <cp...@us...> - 2005-07-04 06:06:38
|
Update of /cvsroot/pclasses/pclasses2/src/App In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4563/src/App Modified Files: LogManager.cpp Log Message: - Added LogManager::initConfig() Index: LogManager.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/App/LogManager.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- LogManager.cpp 1 Jul 2005 12:07:00 -0000 1.5 +++ LogManager.cpp 4 Jul 2005 06:06:26 -0000 1.6 @@ -19,6 +19,9 @@ ***************************************************************************/ #include "pclasses/Phoenix.h" +#include "pclasses/Trace.h" +#include "pclasses/IO/URL.h" +#include "pclasses/App/Config.h" #include "pclasses/App/LogTarget.h" #include "pclasses/App/LogChannel.h" #include "pclasses/App/LogManager.h" @@ -33,6 +36,8 @@ LogManager::~LogManager() throw() { + P_TRACE(LogManager) << "cleaning up ..."; + System::CriticalSection::ScopedLock lck(_channelsMtx); // delete our LogChannels ... @@ -58,6 +63,93 @@ } } +void LogManager::initFromConfig(Config* cfg) +{ + try + { + ConfigSection& logCfgSection = cfg->root().section("Logging", false); + + StringList<std::string> logTargets = + logCfgSection.value("Targets", false); + + LogManager& logMgr = LogManager::instance(); + + StringList<std::string>::const_iterator si = logTargets.begin(); + while(si != logTargets.end()) + { + P_TRACE(LogManager) << "initFromConfig(): initializing LogTarget '" << *si << "'"; + + try + { + ConfigSection& logTargetSection = logCfgSection.section(*si); + + std::string logTargetType = logTargetSection.value("Type", false); + + IO::URL logTargetURL = logTargetSection.value("URL", false); + + std::string logTargetLevel = + logTargetSection.value("LogLevel", std::string("Warning"), false); + + P_TRACE(LogManager) << "initFromConfig(): Type=" << logTargetType + << ", URL=" << logTargetURL + << ", LogLevel=" << logTargetLevel; + + LogTarget* logTarget = logMgr.addTarget(*si, logTargetType); + if(!logTarget) + { + P_TRACE(LogManager) << "initFromConfig(): could not create LogTarget"; + ++si; + continue; + } + + try + { + logTarget->open(logTargetURL); + } + catch(...) + { + P_TRACE(LogManager) << "initFromConfig(): could not open target"; + ++si; + continue; + } + + StringList<std::string> logTargetChannels = + logTargetSection.value("Channels", false); + + StringList<std::string>::const_iterator ci = + logTargetChannels.begin(); + + while(ci != logTargetChannels.end()) + { + P_TRACE(LogManager) << "initFromConfig(): adding target to channel '" << *ci << "'"; + + LogChannel* logChannel = logMgr.channel(*ci); + if(!logChannel) + { + P_TRACE(LogManager) << "initFromConfig(): could not add target to channel '" + << *ci << "'"; + ++ci; + continue; + } + + logChannel->addTarget(logTarget); + ++ci; + } + } + catch(...) + { + P_TRACE(LogManager) << "initFromConfig(): config error, skipping target '" << *si << "'"; + } + + ++si; + } + } + catch(...) + { + P_TRACE(LogManager) << "initFromConfig(): config error, could not init logging"; + } +} + void LogManager::reload() throw() { System::CriticalSection::ScopedLock lck(_targetsMtx); @@ -131,7 +223,7 @@ // create the new target ... else { - target = LogTargetFactory::instance().create(type); + target = LogTargetFactory::instance().create("LogTarget_" + type); if(target) _targets.insert(std::make_pair(name, target)); } |