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 | |
parent | Fixed bug 1647 (diff) | |
download | ice-22d5c2d7e762d35a0f46fe29c3aab8f7e5ae5b7c.tar.bz2 ice-22d5c2d7e762d35a0f46fe29c3aab8f7e5ae5b7c.tar.xz ice-22d5c2d7e762d35a0f46fe29c3aab8f7e5ae5b7c.zip |
Added process logger
-rw-r--r-- | cpp/CHANGES | 6 | ||||
-rw-r--r-- | cpp/include/Ice/Initialize.h | 3 | ||||
-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 | ||||
-rw-r--r-- | cs/CHANGES | 6 | ||||
-rwxr-xr-x | cs/src/Ice/Instance.cs | 2 | ||||
-rwxr-xr-x | cs/src/Ice/PluginManagerI.cs | 1 | ||||
-rwxr-xr-x | cs/src/Ice/PropertiesI.cs | 8 | ||||
-rwxr-xr-x | cs/src/Ice/Util.cs | 24 | ||||
-rw-r--r-- | java/CHANGES | 6 | ||||
-rw-r--r-- | java/src/Ice/PropertiesI.java | 7 | ||||
-rw-r--r-- | java/src/Ice/Util.java | 28 | ||||
-rw-r--r-- | java/src/IceInternal/Instance.java | 2 |
15 files changed, 114 insertions, 21 deletions
diff --git a/cpp/CHANGES b/cpp/CHANGES index d15ad6b25ad..447d6e99261 100644 --- a/cpp/CHANGES +++ b/cpp/CHANGES @@ -1,6 +1,12 @@ Changes since version 3.1.1 --------------------------- +- Added a per-process logger and two methods to get/set the logger, + Ice::getProcessLogger() and Ice::setProcessLogger(). Get will create a + default process logger when called if set has not been called. The + process logger will also be used as the default logger for all + communicators that do not have a logger explicitly set. + - Added new property, Glacier2.ReturnClientProxy to control whether the Glacier2 Router::getClientProxy() returns a proxy or just null. By default this property is set to 0. If Glacier2 is being used by clients diff --git a/cpp/include/Ice/Initialize.h b/cpp/include/Ice/Initialize.h index 0ba05a05c2d..e7b3ff3b56b 100644 --- a/cpp/include/Ice/Initialize.h +++ b/cpp/include/Ice/Initialize.h @@ -85,6 +85,9 @@ ICE_API ICE_DEPRECATED_API CommunicatorPtr initializeWithPropertiesAndLogger(int ICE_API InputStreamPtr createInputStream(const CommunicatorPtr&, const ::std::vector< Byte >&); ICE_API OutputStreamPtr createOutputStream(const CommunicatorPtr&); +ICE_API LoggerPtr getProcessLogger(); +ICE_API void setProcessLogger(const LoggerPtr&); + } namespace IceInternal 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); } } } diff --git a/cs/CHANGES b/cs/CHANGES index b5b4a181f57..c0dd905c31b 100644 --- a/cs/CHANGES +++ b/cs/CHANGES @@ -1,6 +1,12 @@ Changes since version 3.1.1 --------------------------- +- Added a per-process logger and two methods to get/set the logger, + Ice.Util.getProcessLogger() and Ice.Util.setProcessLogger(). Get will + create a default process logger when called if set has not been called. + he process logger will also be used as the default logger for all + communicators that do not have a logger explicitly set. + - Message batches are now automatically flushed when the total size of the batch reaches the message size maximum. diff --git a/cs/src/Ice/Instance.cs b/cs/src/Ice/Instance.cs index ca581f40123..1be9a73c0a7 100755 --- a/cs/src/Ice/Instance.cs +++ b/cs/src/Ice/Instance.cs @@ -379,7 +379,7 @@ namespace IceInternal } else { - _initData.logger = new Ice.LoggerI(_initData.properties.getProperty("Ice.ProgramName")); + _initData.logger = Ice.Util.getProcessLogger(); } } diff --git a/cs/src/Ice/PluginManagerI.cs b/cs/src/Ice/PluginManagerI.cs index 090068356c2..fbee4809f61 100755 --- a/cs/src/Ice/PluginManagerI.cs +++ b/cs/src/Ice/PluginManagerI.cs @@ -432,5 +432,4 @@ namespace Ice private Logger _logger = null; private bool _initialized; } - } diff --git a/cs/src/Ice/PropertiesI.cs b/cs/src/Ice/PropertiesI.cs index 2303f4a4295..33f0ccc2064 100755 --- a/cs/src/Ice/PropertiesI.cs +++ b/cs/src/Ice/PropertiesI.cs @@ -90,10 +90,10 @@ namespace Ice return; } - // Check if the property is legal. (We write to Console.Error instead of using - // a logger because no logger may be established at the time the property - // is parsed.) // + // Check if the property is legal. + // + Logger logger = Ice.Util.getProcessLogger(); int dotPos = key.IndexOf('.'); if(dotPos != -1) { @@ -118,7 +118,7 @@ namespace Ice } if(!found) { - System.Console.Error.WriteLine("warning: unknown property: " + key); + logger.warning("unknown property: " + key); } } } diff --git a/cs/src/Ice/Util.cs b/cs/src/Ice/Util.cs index 2d93bc53fb3..3704148313b 100755 --- a/cs/src/Ice/Util.cs +++ b/cs/src/Ice/Util.cs @@ -448,6 +448,28 @@ namespace Ice { return new OutputStreamI(communicator); } - } + public static Logger getProcessLogger() + { + lock(_processLoggerMutex) + { + if(_processLogger == null) + { + _processLogger = new LoggerI(System.AppDomain.CurrentDomain.FriendlyName); + } + return _processLogger; + } + } + + public static void setProcessLogger(Logger logger) + { + lock(_processLoggerMutex) + { + _processLogger = logger; + } + } + + private static object _processLoggerMutex = new object(); + private static Logger _processLogger = null; + } } diff --git a/java/CHANGES b/java/CHANGES index 3920849a808..9dfcbf05699 100644 --- a/java/CHANGES +++ b/java/CHANGES @@ -1,6 +1,12 @@ Changes since version 3.1.1 --------------------------- +- Added a per-process logger and two methods to get/set the logger, + Ice.Util.getProcessLogger() and Ice.Util.setProcessLogger(). Get will + create a default process logger when called if set has not been called. + The process logger will also be used as the default logger for all + communicators that do not have a logger explicitly set. + - Added support to Ice.Application for shutdown hooks. See Ice.Application.setInterruptHook for details. diff --git a/java/src/Ice/PropertiesI.java b/java/src/Ice/PropertiesI.java index 3afe19d520c..bed28124d00 100644 --- a/java/src/Ice/PropertiesI.java +++ b/java/src/Ice/PropertiesI.java @@ -92,10 +92,9 @@ public final class PropertiesI extends LocalObjectImpl implements Properties setProperty(String key, String value) { // - // Check if the property is legal. (We write to System.err instead of using - // a logger because no logger may be established at the time the property - // is parsed.) + // Check if the property is legal. // + Logger logger = Ice.Util.getProcessLogger(); if(key == null || key.length() == 0) { return; @@ -126,7 +125,7 @@ public final class PropertiesI extends LocalObjectImpl implements Properties } if(!found) { - System.err.println("warning: unknown property: " + key); + logger.warning("unknown property: " + key); } } } diff --git a/java/src/Ice/Util.java b/java/src/Ice/Util.java index 586d5fb3162..df0254f0e07 100644 --- a/java/src/Ice/Util.java +++ b/java/src/Ice/Util.java @@ -382,5 +382,33 @@ public final class Util return new OutputStreamI(communicator); } + public static Logger + getProcessLogger() + { + synchronized(_processLoggerMutex) + { + if(_processLogger == null) + { + // + // TODO: Would be nice to be able to use process name as prefix by default. + // + _processLogger = new LoggerI(""); + } + + return _processLogger; + } + } + + public static void + setProcessLogger(Logger logger) + { + synchronized(_processLoggerMutex) + { + _processLogger = logger; + } + } + private static String _localAddress = null; + private static java.lang.Object _processLoggerMutex = new java.lang.Object(); + private static Logger _processLogger = null; } diff --git a/java/src/IceInternal/Instance.java b/java/src/IceInternal/Instance.java index a2a82c6d21b..ece93c9b020 100644 --- a/java/src/IceInternal/Instance.java +++ b/java/src/IceInternal/Instance.java @@ -368,7 +368,7 @@ public final class Instance } else { - _initData.logger = new Ice.LoggerI(_initData.properties.getProperty("Ice.ProgramName")); + _initData.logger = Ice.Util.getProcessLogger(); } } |