diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2007-01-04 16:36:09 +0000 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2007-01-04 16:36:09 +0000 |
commit | 22d5c2d7e762d35a0f46fe29c3aab8f7e5ae5b7c (patch) | |
tree | d18c790a8e35de14015ddd7b14c49bcb19c28b5b /cpp/src | |
parent | Fixed bug 1647 (diff) | |
download | ice-22d5c2d7e762d35a0f46fe29c3aab8f7e5ae5b7c.tar.bz2 ice-22d5c2d7e762d35a0f46fe29c3aab8f7e5ae5b7c.tar.xz ice-22d5c2d7e762d35a0f46fe29c3aab8f7e5ae5b7c.zip |
Added process logger
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Ice/CommunicatorI.cpp | 6 | ||||
-rw-r--r-- | cpp/src/Ice/Initialize.cpp | 26 | ||||
-rw-r--r-- | cpp/src/Ice/Instance.cpp | 2 | ||||
-rw-r--r-- | cpp/src/Ice/PropertiesI.cpp | 8 |
4 files changed, 33 insertions, 9 deletions
diff --git a/cpp/src/Ice/CommunicatorI.cpp b/cpp/src/Ice/CommunicatorI.cpp index d56d618eaa8..1bdeb18fc40 100644 --- a/cpp/src/Ice/CommunicatorI.cpp +++ b/cpp/src/Ice/CommunicatorI.cpp @@ -48,7 +48,6 @@ static IceUtil::StaticMutex gcMutex = ICE_STATIC_MUTEX_INITIALIZER; static GarbageCollectorStats gcStats; static int gcTraceLevel; static string gcTraceCat; -static LoggerPtr gcLogger; static int gcInterval; static void @@ -58,7 +57,7 @@ printGCStats(const IceInternal::GCStats& stats) { if(gcTraceLevel > 1) { - Trace out(gcLogger, gcTraceCat); + Trace out(getProcessLogger(), gcTraceCat); out << stats.collected << "/" << stats.examined << ", " << stats.time * 1000 << "ms"; } ++gcStats.runs; @@ -94,7 +93,7 @@ Ice::CommunicatorI::destroy() { if(gcTraceLevel) { - Trace out(gcLogger, gcTraceCat); + Trace out(getProcessLogger(), gcTraceCat); out << "totals: " << gcStats.collected << "/" << gcStats.examined << ", " << gcStats.time * 1000 << "ms" << ", " << gcStats.runs << " run"; if(gcStats.runs != 1) @@ -287,7 +286,6 @@ Ice::CommunicatorI::CommunicatorI(const InitializationData& initData) { gcTraceLevel = _instance->traceLevels()->gc; gcTraceCat = _instance->traceLevels()->gcCat; - gcLogger = _instance->initializationData().logger; gcInterval = _instance->initializationData().properties->getPropertyAsInt("Ice.GC.Interval"); gcOnce = false; } diff --git a/cpp/src/Ice/Initialize.cpp b/cpp/src/Ice/Initialize.cpp index b8b0af03cf5..1ec9985dfec 100644 --- a/cpp/src/Ice/Initialize.cpp +++ b/cpp/src/Ice/Initialize.cpp @@ -13,6 +13,7 @@ #include <Ice/Initialize.h> #include <Ice/LocalException.h> #include <Ice/StreamI.h> +#include <Ice/LoggerI.h> using namespace std; using namespace Ice; @@ -245,6 +246,31 @@ Ice::createOutputStream(const CommunicatorPtr& communicator) return new OutputStreamI(communicator); } +static IceUtil::StaticMutex processLoggerMutex = ICE_STATIC_MUTEX_INITIALIZER; +static Ice::LoggerPtr processLogger; + +LoggerPtr +Ice::getProcessLogger() +{ + IceUtil::StaticMutex::Lock lock(processLoggerMutex); + + if(processLogger == 0) + { + // + // TODO: Would be nice to be able to use process name as prefix by default. + // + processLogger = new Ice::LoggerI(""); + } + return processLogger; +} + +void +setProcessLogger(const LoggerPtr& logger) +{ + IceUtil::StaticMutex::Lock lock(processLoggerMutex); + processLogger = logger; +} + InstancePtr IceInternal::getInstance(const CommunicatorPtr& communicator) { diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp index 8cf07bdf2e4..7ad6fd88321 100644 --- a/cpp/src/Ice/Instance.cpp +++ b/cpp/src/Ice/Instance.cpp @@ -592,7 +592,7 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const Initi #endif else { - _initData.logger = new LoggerI(_initData.properties->getProperty("Ice.ProgramName")); + _initData.logger = getProcessLogger(); } } diff --git a/cpp/src/Ice/PropertiesI.cpp b/cpp/src/Ice/PropertiesI.cpp index e160fe6cf8f..dc487794700 100644 --- a/cpp/src/Ice/PropertiesI.cpp +++ b/cpp/src/Ice/PropertiesI.cpp @@ -13,6 +13,7 @@ #include <Ice/Initialize.h> #include <Ice/LocalException.h> #include <Ice/PropertyNames.h> +#include <Ice/Logger.h> #include <fstream> using namespace std; @@ -102,10 +103,9 @@ Ice::PropertiesI::setProperty(const string& key, const string& value) } // - // Check if the property is legal. (We write to cerr instead of - // using a logger because no logger may be established at the time - // the property is parsed.) + // Check if the property is legal. // + LoggerPtr logger = getProcessLogger(); string::size_type dotPos = key.find('.'); if(dotPos != string::npos) { @@ -128,7 +128,7 @@ Ice::PropertiesI::setProperty(const string& key, const string& value) } if(!found) { - cerr << "warning: unknown property: " << key << endl; + logger->warning("unknown property: " + key); } } } |