diff options
author | Bernard Normier <bernard@zeroc.com> | 2014-08-14 16:38:21 -0400 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2014-08-14 16:38:21 -0400 |
commit | 18748d529095d3ab86e3dc42abfd2b5f4946f9a7 (patch) | |
tree | 1f343c0790d98e7fbcff50ad94ea5c1e272b2d4f /cpp/src | |
parent | Fixed ice_invocationTimout usage in IceDiscovery hello demos (diff) | |
download | ice-18748d529095d3ab86e3dc42abfd2b5f4946f9a7.tar.bz2 ice-18748d529095d3ab86e3dc42abfd2b5f4946f9a7.tar.xz ice-18748d529095d3ab86e3dc42abfd2b5f4946f9a7.zip |
Initial merge for ICE-2400:
- added new Logger admin facet (C++ only)
- this Logger facet allows remote application to retrieve the Ice log file, including recently logged events, with optional filters
- this logger facet also allows remote applications to attach RemoteLogger objects to get new logs as they are generated
- added new "show log" feature to icegridadmin, to retrieve Ice log file of Ice server (not yet implemented for IceGrid registry and node)
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Ice/.depend.mak | 9 | ||||
-rw-r--r-- | cpp/src/Ice/CommunicatorI.cpp | 2 | ||||
-rw-r--r-- | cpp/src/Ice/Instance.cpp | 115 | ||||
-rw-r--r-- | cpp/src/Ice/Instance.h | 2 | ||||
-rw-r--r-- | cpp/src/Ice/LoggerAdminI.cpp | 873 | ||||
-rw-r--r-- | cpp/src/Ice/LoggerAdminI.h | 53 | ||||
-rw-r--r-- | cpp/src/Ice/LoggerI.cpp | 15 | ||||
-rw-r--r-- | cpp/src/Ice/LoggerI.h | 4 | ||||
-rw-r--r-- | cpp/src/Ice/Makefile | 4 | ||||
-rw-r--r-- | cpp/src/Ice/Makefile.mak | 3 | ||||
-rw-r--r-- | cpp/src/Ice/PropertyNames.cpp | 6 | ||||
-rw-r--r-- | cpp/src/Ice/PropertyNames.h | 2 | ||||
-rw-r--r-- | cpp/src/Ice/ProtocolInstance.cpp | 2 | ||||
-rw-r--r-- | cpp/src/Ice/ProtocolInstance.h | 4 | ||||
-rw-r--r-- | cpp/src/Ice/Service.cpp | 32 | ||||
-rw-r--r-- | cpp/src/Ice/SysLoggerI.cpp | 13 | ||||
-rw-r--r-- | cpp/src/Ice/SysLoggerI.h | 2 | ||||
-rw-r--r-- | cpp/src/IceBox/ServiceManagerI.cpp | 31 | ||||
-rw-r--r-- | cpp/src/IceGrid/Grammar.cpp | 380 | ||||
-rw-r--r-- | cpp/src/IceGrid/Grammar.h | 7 | ||||
-rw-r--r-- | cpp/src/IceGrid/Grammar.y | 6 | ||||
-rw-r--r-- | cpp/src/IceGrid/Parser.cpp | 350 | ||||
-rw-r--r-- | cpp/src/IceGrid/Parser.h | 8 | ||||
-rw-r--r-- | cpp/src/IceGrid/Scanner.cpp | 6 |
24 files changed, 1628 insertions, 301 deletions
diff --git a/cpp/src/Ice/.depend.mak b/cpp/src/Ice/.depend.mak index d9e05938186..088e886c25a 100644 --- a/cpp/src/Ice/.depend.mak +++ b/cpp/src/Ice/.depend.mak @@ -148,3 +148,12 @@ $(HDIR)\ServantLocatorF.h ServantLocatorF.cpp: "$(slicedir)/Ice/ServantLocatorF. $(HDIR)\ServantLocator.h ServantLocator.cpp: "$(slicedir)/Ice/ServantLocator.ice" "$(slicedir)/Ice/ObjectAdapterF.ice" "$(slicedir)/Ice/Current.ice" "$(slicedir)/Ice/ConnectionF.ice" "$(slicedir)/Ice/Identity.ice" "$(slicedir)/Ice/Version.ice" "$(SLICE2CPP)" "$(SLICEPARSERLIB)" $(HDIR)\SliceChecksumDict.h SliceChecksumDict.cpp: "$(slicedir)/Ice/SliceChecksumDict.ice" "$(SLICE2CPP)" "$(SLICEPARSERLIB)" $(HDIR)\Version.h Version.cpp: "$(slicedir)/Ice/Version.ice" "$(SLICE2CPP)" "$(SLICEPARSERLIB)" + +RemoteLogger$(OBJEXT): RemoteLogger.cpp "$(includedir)/Ice/RemoteLogger.h" +$(HDIR)\RemoteLogger.h RemoteLogger.cpp: "$(slicedir)/Ice/RemoteLogger.ice" "$(SLICE2CPP)" "$(SLICEPARSERLIB)" + + + + + + diff --git a/cpp/src/Ice/CommunicatorI.cpp b/cpp/src/Ice/CommunicatorI.cpp index 820d5fee400..7f225c425e0 100644 --- a/cpp/src/Ice/CommunicatorI.cpp +++ b/cpp/src/Ice/CommunicatorI.cpp @@ -361,7 +361,7 @@ Ice::CommunicatorI::finishSetup(int& argc, char* argv[]) { try { - _instance->finishSetup(argc, argv); + _instance->finishSetup(argc, argv, this); } catch(...) { diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp index 8bf1162ce8d..52c29e7d3b9 100644 --- a/cpp/src/Ice/Instance.cpp +++ b/cpp/src/Ice/Instance.cpp @@ -39,7 +39,7 @@ #include <Ice/MetricsAdminI.h> #include <Ice/InstrumentationI.h> #include <Ice/ProtocolInstance.h> - +#include <Ice/LoggerAdminI.h> #include <IceUtil/UUID.h> #include <IceUtil/Mutex.h> #include <IceUtil/MutexPtrLock.h> @@ -1207,44 +1207,6 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const Initi _wstringConverter = new IceUtil::UnicodeWstringConverter(); } - // - // Add Process and Properties facets - // - - StringSeq facetSeq = _initData.properties->getPropertyAsList("Ice.Admin.Facets"); - - if(!facetSeq.empty()) - { - _adminFacetFilter.insert(facetSeq.begin(), facetSeq.end()); - } - - _adminFacets.insert(FacetMap::value_type("Process", new ProcessI(communicator))); - - PropertiesAdminIPtr props = new PropertiesAdminI("Properties", _initData.properties, _initData.logger); - _adminFacets.insert(FacetMap::value_type("Properties",props)); - - _metricsAdmin = new MetricsAdminI(_initData.properties, _initData.logger); - _adminFacets.insert(FacetMap::value_type("Metrics", _metricsAdmin)); - - // - // Setup the communicator observer only if the user didn't already set an - // Ice observer resolver and if the admininistrative endpoints are set. - // - if((_adminFacetFilter.empty() || _adminFacetFilter.find("Metrics") != _adminFacetFilter.end()) && - _initData.properties->getProperty("Ice.Admin.Endpoints") != "") - { - _observer = new CommunicatorObserverI(_metricsAdmin, _initData.observer); - - // - // Make sure the admin plugin receives property updates. - // - props->addUpdateCallback(_metricsAdmin); - } - else - { - _observer = _initData.observer; - } - __setNoDelete(false); } catch(...) @@ -1303,7 +1265,7 @@ IceInternal::Instance::~Instance() } void -IceInternal::Instance::finishSetup(int& argc, char* argv[]) +IceInternal::Instance::finishSetup(int& argc, char* argv[], const Ice::CommunicatorPtr& communicator) { // // Load plug-ins. @@ -1314,6 +1276,70 @@ IceInternal::Instance::finishSetup(int& argc, char* argv[]) pluginManagerImpl->loadPlugins(argc, argv); // + // Add admin facets + // Note that any logger-dependent admin facet must be created after we load all plugins, + // since one of these plugins can be a Logger plugin that sets a new logger during loading + // + + StringSeq facetSeq = _initData.properties->getPropertyAsList("Ice.Admin.Facets"); + + if(!facetSeq.empty()) + { + _adminFacetFilter.insert(facetSeq.begin(), facetSeq.end()); + } + _adminFacets.insert(FacetMap::value_type("Process", new ProcessI(communicator))); + + string loggerFacetName = _initData.properties->getPropertyWithDefault("Ice.Admin.Logger", "Logger"); + + bool insertLoggerFacet = + (_adminFacetFilter.empty() || _adminFacetFilter.find(loggerFacetName) != _adminFacetFilter.end()) && + _initData.properties->getProperty("Ice.Admin.Endpoints") != ""; + + if(loggerFacetName != "Logger" || insertLoggerFacet) + { + // + // Set up a new Logger + // + Ice::LoggerAdminLoggerPtr logger = createLoggerAdminLogger(loggerFacetName, + _initData.properties, + _initData.logger); + setLogger(logger); + + if(insertLoggerFacet) + { + logger->addAdminFacet(communicator); + } + // + // Else, this new logger & facet is useful for "slave" communicators like IceBox services. + // + } + + PropertiesAdminIPtr props = new PropertiesAdminI("Properties", _initData.properties, _initData.logger); + _adminFacets.insert(FacetMap::value_type("Properties", props)); + + _metricsAdmin = new MetricsAdminI(_initData.properties, _initData.logger); + _adminFacets.insert(FacetMap::value_type("Metrics", _metricsAdmin)); + + // + // Setup the communicator observer only if the user didn't already set an + // Ice observer resolver and if the admininistrative endpoints are set. + // + if((_adminFacetFilter.empty() || _adminFacetFilter.find("Metrics") != _adminFacetFilter.end()) && + _initData.properties->getProperty("Ice.Admin.Endpoints") != "") + { + _observer = new CommunicatorObserverI(_metricsAdmin, _initData.observer); + + // + // Make sure the admin plugin receives property updates. + // + props->addUpdateCallback(_metricsAdmin); + } + else + { + _observer = _initData.observer; + } + + // // Set observer updater // if(_observer) @@ -1491,6 +1517,15 @@ IceInternal::Instance::destroy() _observer->setObserverUpdater(0); // Break cyclic reference count. } } + + Ice::LoggerAdminLoggerPtr logger = Ice::LoggerAdminLoggerPtr::dynamicCast(_initData.logger); + if(logger) + { + // + // This only disables the remote logging; we don't set or reset _initData.logger + // + logger->destroy(); + } ThreadPoolPtr serverThreadPool; ThreadPoolPtr clientThreadPool; diff --git a/cpp/src/Ice/Instance.h b/cpp/src/Ice/Instance.h index 9373b960fda..e9806b307a6 100644 --- a/cpp/src/Ice/Instance.h +++ b/cpp/src/Ice/Instance.h @@ -120,7 +120,7 @@ private: Instance(const Ice::CommunicatorPtr&, const Ice::InitializationData&); virtual ~Instance(); - void finishSetup(int&, char*[]); + void finishSetup(int&, char*[], const Ice::CommunicatorPtr&); void destroy(); friend class Ice::CommunicatorI; diff --git a/cpp/src/Ice/LoggerAdminI.cpp b/cpp/src/Ice/LoggerAdminI.cpp new file mode 100644 index 00000000000..299f3718087 --- /dev/null +++ b/cpp/src/Ice/LoggerAdminI.cpp @@ -0,0 +1,873 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include <Ice/LoggerAdminI.h> +#include <Ice/RemoteLogger.h> +#include <Ice/Properties.h> +#include <Ice/ObjectAdapter.h> +#include <Ice/Communicator.h> +#include <Ice/Connection.h> +#include <Ice/LocalException.h> +#include <Ice/LoggerUtil.h> + +#include <set> + +using namespace std; + +namespace +{ + +class LoggerAdminI : public Ice::LoggerAdmin +{ +public: + + LoggerAdminI(const string&, const Ice::PropertiesPtr&); + + virtual void attachRemoteLogger(const Ice::RemoteLoggerPrx&, const Ice::LogMessageTypeSeq&, + const Ice::StringSeq&, Ice::Int, const Ice::Current&); + + virtual void detachRemoteLogger(const Ice::RemoteLoggerPrx&, const Ice::Current&); + + virtual Ice::LogMessageSeq getLog(const Ice::LogMessageTypeSeq&, + const Ice::StringSeq&, Ice::Int, string&, + const Ice::Current&); + + vector<Ice::RemoteLoggerPrx> log(const Ice::LogMessage&); + + void deadRemoteLogger(const Ice::RemoteLoggerPrx&, + const Ice::LoggerPtr&, + const Ice::LocalException&, const string&); + + void run(const Ice::LoggerPtr&); + void destroy(); + + const string& getFacetName() const + { + return _facetName; + } + + const int getTraceLevel() const + { + return _traceLevel; + } + +private: + + bool removeRemoteLogger(const Ice::RemoteLoggerPrx&); + + void remoteCallCompleted(const Ice::AsyncResultPtr&); + + const string _facetName; + + IceUtil::Monitor<IceUtil::Mutex> _monitor; + list<Ice::LogMessage> _queue; + int _logCount; // non-trace messages + const int _maxLogCount; + int _traceCount; + const int _maxTraceCount; + const int _traceLevel; + IceUtil::Time _pingPeriod; + + list<Ice::LogMessage>::iterator _oldestTrace; + list<Ice::LogMessage>::iterator _oldestLog; + + struct ObjectIdentityCompare + { + bool operator()(const Ice::RemoteLoggerPrx& lhs, const Ice::RemoteLoggerPrx& rhs) + { + // + // Caller should make sure that proxies are never null + // + assert(lhs != 0 && rhs != 0); + + return lhs->ice_getIdentity() < rhs->ice_getIdentity(); + } + }; + + struct Filters + { + Filters(const Ice::LogMessageTypeSeq& m, const Ice::StringSeq& c) : + messageTypes(m.begin(), m.end()), + traceCategories(c.begin(), c.end()) + { + } + + const set<Ice::LogMessageType> messageTypes; + const set<string> traceCategories; + }; + + typedef map<Ice::RemoteLoggerPrx, Filters, ObjectIdentityCompare> RemoteLoggerMap; + + struct GetRemoteLoggerMapKey + { + RemoteLoggerMap::key_type + operator()(const RemoteLoggerMap::value_type& val) + { + return val.first; + } + }; + + RemoteLoggerMap _remoteLoggerMap; + + const Ice::CallbackPtr _remoteCallCompleted; + + bool _destroyed; + bool _pingThreadStarted; + IceUtil::ThreadControl _pingThreadControl; +}; +typedef IceUtil::Handle<LoggerAdminI> LoggerAdminIPtr; + + +class PingThread : public IceUtil::Thread +{ +public: + PingThread(const LoggerAdminIPtr&, const Ice::LoggerPtr&); + + virtual void run(); + +private: + + LoggerAdminIPtr _loggerAdmin; + Ice::LoggerPtr _logger; +}; + + +class Job : public IceUtil::Shared +{ +public: + + Job(const vector<Ice::RemoteLoggerPrx>& r, const Ice::LogMessage& l) : + remoteLoggers(r), + logMessage(l) + { + } + + const vector<Ice::RemoteLoggerPrx> remoteLoggers; + const Ice::LogMessage logMessage; +}; +typedef IceUtil::Handle<Job> JobPtr; + + +class LoggerAdminLoggerI : public Ice::LoggerAdminLogger +{ +public: + + LoggerAdminLoggerI(const std::string&, const Ice::PropertiesPtr&, const Ice::LoggerPtr&); + + virtual void print(const std::string&); + virtual void trace(const std::string&, const std::string&); + virtual void warning(const std::string&); + virtual void error(const std::string&); + virtual std::string getPrefix(); + virtual Ice::LoggerPtr cloneWithPrefix(const std::string&); + + virtual void addAdminFacet(const Ice::CommunicatorPtr&); + virtual void destroy(); + + void run(); + +private: + + void log(const Ice::LogMessage&); + + const Ice::LoggerPtr _localLogger; + const LoggerAdminIPtr _loggerAdmin; + + IceUtil::Monitor<IceUtil::Mutex> _monitor; + + bool _destroyed; + bool _sendLogThreadStarted; + IceUtil::ThreadControl _sendLogThreadControl; + std::deque<JobPtr> _jobQueue; +}; +typedef IceUtil::Handle<LoggerAdminLoggerI> LoggerAdminLoggerIPtr; + + +class SendLogThread : public IceUtil::Thread +{ +public: + + SendLogThread(const LoggerAdminLoggerIPtr&); + + virtual void run(); + +private: + + LoggerAdminLoggerIPtr _logger; +}; + + +// +// Filter out messages from in/out logMessages list +// +void +filterLogMessages(Ice::LogMessageSeq& logMessages, const set<Ice::LogMessageType>& messageTypes, + const set<string>& traceCategories, Ice::Int messageMax) +{ + if(messageMax == 0) + { + logMessages.clear(); + } + + // + // Filter only if one of the 3 filters is set; messageMax < 0 means "give me all" + // that match the other filters, if any. + // + else if(!messageTypes.empty() || !traceCategories.empty() || messageMax > 0) + { + int count = 0; + Ice::LogMessageSeq::reverse_iterator p = logMessages.rbegin(); + while(p != logMessages.rend()) + { + bool keepIt = false; + if(messageTypes.empty() || messageTypes.count(p->type) != 0) + { + if(p->type != Ice::TraceMessage || traceCategories.empty() || + traceCategories.count(p->traceCategory) != 0) + { + keepIt = true; + } + } + + if(keepIt) + { + ++p; + ++count; + if(messageMax > 0 && count >= messageMax) + { + // + // p.base() points to p "+1"; note that this invalidates p. + // + logMessages.erase(logMessages.begin(), p.base()); + break; // while + } + } + else + { + ++p; + // + // p.base() points to p "+1"; the erase invalidates p so we + // need to rebuild it + // + p = Ice::LogMessageSeq::reverse_iterator(logMessages.erase(p.base())); + } + } + } + // else, don't need any filtering +} + + + +// +// LoggerAdminI +// + +LoggerAdminI::LoggerAdminI(const string& name, const Ice::PropertiesPtr& props) : + _facetName(name), + _logCount(0), + _maxLogCount(props->getPropertyAsIntWithDefault("Ice.Admin.Logger.KeepLogs", 100)), + _traceCount(0), + _maxTraceCount(props->getPropertyAsIntWithDefault("Ice.Admin.Logger.KeepTraces", 100)), + _traceLevel(props->getPropertyAsInt("Ice.Trace.Admin.Logger")), + _remoteCallCompleted(Ice::newCallback(this, &LoggerAdminI::remoteCallCompleted)), + _destroyed(false), + _pingThreadStarted(false) +{ + int pingPeriod = props->getPropertyAsIntWithDefault("Ice.Admin.Logger.PingPeriod", 60); + if(pingPeriod < 10) + { + pingPeriod = 10; + } + _pingPeriod = IceUtil::Time::seconds(pingPeriod); + + _oldestLog = _queue.end(); + _oldestTrace = _queue.end(); +} + +void +LoggerAdminI::attachRemoteLogger(const Ice::RemoteLoggerPrx& prx, + const Ice::LogMessageTypeSeq& messageTypes, + const Ice::StringSeq& categories, + Ice::Int messageMax, + const Ice::Current& current) +{ + if(prx == 0) + { + return; // can't send this null RemoteLogger anything! + } + + Ice::RemoteLoggerPrx remoteLogger = prx->ice_oneway(); + Filters filters(messageTypes, categories); + + Ice::LogMessageSeq initLogMessages; + Ice::LoggerPtr logger = current.adapter->getCommunicator()->getLogger(); + + { + IceUtil::Monitor<IceUtil::Mutex>::Lock lock(_monitor); + + if(_remoteLoggerMap.insert(make_pair(remoteLogger, filters)).second == false) + { + if(_traceLevel > 0) + { + Ice::Trace trace(current.adapter->getCommunicator()->getLogger(), _facetName); + trace << "rejecting '" << remoteLogger << "' with RemoteLoggerAlreadyAttachedException"; + } + + throw Ice::RemoteLoggerAlreadyAttachedException(); + } + + if(_pingThreadStarted == false) + { + IceUtil::ThreadPtr t = new PingThread(this, logger); + _pingThreadControl = t->start(); + _pingThreadStarted = true; + } + + if(messageMax != 0) + { + initLogMessages = _queue; // copy + } + } + + if(_traceLevel > 0) + { + Ice::Trace trace(logger, _facetName); + trace << "sending init to '" << remoteLogger->ice_twoway() << "'"; + } + + filterLogMessages(initLogMessages, filters.messageTypes, filters.traceCategories, messageMax); + + try + { + remoteLogger->ice_twoway()->begin_init(logger->getPrefix(), initLogMessages, _remoteCallCompleted, logger); + } + catch(const Ice::LocalException& ex) + { + deadRemoteLogger(remoteLogger, logger, ex, "init"); + throw; + } +} + +void +LoggerAdminI::detachRemoteLogger(const Ice::RemoteLoggerPrx& remoteLogger, + const Ice::Current& current) +{ + if(remoteLogger == 0) + { + throw Ice::RemoteLoggerNotAttachedException(); + } + + bool found = removeRemoteLogger(remoteLogger); + + if(!found) + { + throw Ice::RemoteLoggerNotAttachedException(); + } + + if(_traceLevel > 0) + { + Ice::Trace trace(current.adapter->getCommunicator()->getLogger(), _facetName); + trace << "detached '" << remoteLogger << "'"; + } +} + +Ice::LogMessageSeq +LoggerAdminI::getLog(const Ice::LogMessageTypeSeq& messageTypes, + const Ice::StringSeq& categories, + Ice::Int messageMax, string& prefix, const Ice::Current& current) +{ + Ice::LogMessageSeq logMessages; + { + IceUtil::Monitor<IceUtil::Mutex>::Lock lock(_monitor); + + if(messageMax != 0) + { + logMessages = _queue; + } + } + + Ice::LoggerPtr logger = current.adapter->getCommunicator()->getLogger(); + prefix = logger->getPrefix(); + + Filters filters(messageTypes, categories); + filterLogMessages(logMessages, filters.messageTypes, filters.traceCategories, messageMax); + return logMessages; +} + +vector<Ice::RemoteLoggerPrx> +LoggerAdminI::log(const Ice::LogMessage& logMessage) +{ + vector<Ice::RemoteLoggerPrx> remoteLoggers; + + IceUtil::Monitor<IceUtil::Mutex>::Lock lock(_monitor); + + // + // Put message in _queue + // + if((logMessage.type != Ice::TraceMessage && _maxLogCount > 0) || + (logMessage.type == Ice::TraceMessage && _maxTraceCount > 0)) + { + list<Ice::LogMessage>::iterator p = _queue.insert(_queue.end(), logMessage); + + if(logMessage.type != Ice::TraceMessage) + { + assert(_maxLogCount > 0); + if(_logCount == _maxLogCount) + { + // + // Need to remove the oldest log from the queue + // + assert(_oldestLog != _queue.end()); + _oldestLog = _queue.erase(_oldestLog); + while(_oldestLog != _queue.end() && _oldestLog->type == Ice::TraceMessage) + { + _oldestLog++; + } + assert(_oldestLog != _queue.end()); + } + else + { + assert(_logCount < _maxLogCount); + _logCount++; + if(_oldestLog == _queue.end()) + { + _oldestLog = p; + } + } + } + else + { + assert(_maxTraceCount > 0); + if(_traceCount == _maxTraceCount) + { + // + // Need to remove the oldest trace from the queue + // + assert(_oldestTrace != _queue.end()); + _oldestTrace = _queue.erase(_oldestTrace); + while(_oldestTrace != _queue.end() && _oldestTrace->type != Ice::TraceMessage) + { + _oldestTrace++; + } + assert(_oldestTrace != _queue.end()); + } + else + { + assert(_traceCount < _maxTraceCount); + _traceCount++; + if(_oldestTrace == _queue.end()) + { + _oldestTrace = p; + } + } + } + + // + // Queue updated, now find which remote loggers want this message + // + for(RemoteLoggerMap::const_iterator p = _remoteLoggerMap.begin(); p != _remoteLoggerMap.end(); ++p) + { + const Filters& filters = p->second; + + if(filters.messageTypes.empty() || filters.messageTypes.count(logMessage.type) != 0) + { + if(logMessage.type != Ice::TraceMessage || filters.traceCategories.empty() || + filters.traceCategories.count(logMessage.traceCategory) != 0) + { + remoteLoggers.push_back(p->first); + } + } + } + } + return remoteLoggers; +} + +void +LoggerAdminI::deadRemoteLogger(const Ice::RemoteLoggerPrx& remoteLogger, + const Ice::LoggerPtr& logger, + const Ice::LocalException& ex, + const string& operation) +{ + if(removeRemoteLogger(remoteLogger)) + { + if(_traceLevel > 0) + { + Ice::Trace trace(logger, _facetName); + trace << operation << " on '" << remoteLogger << "' raised '" + << ex << "'; remote logger removed automatically"; + } + } +} + +void +LoggerAdminI::destroy() +{ + IceUtil::ThreadControl pingThreadControl; + bool joinThread = false; + { + IceUtil::Monitor<IceUtil::Mutex>::Lock lock(_monitor); + + if(_pingThreadStarted) + { + joinThread = true; + pingThreadControl = _pingThreadControl; + _pingThreadStarted = false; + _destroyed = true; + _monitor.notifyAll(); + } + } + + if(joinThread) + { + pingThreadControl.join(); + } +} + +void +LoggerAdminI::run(const Ice::LoggerPtr& logger) +{ + if(_traceLevel > 1) + { + Ice::Trace trace(logger, _facetName); + trace << "Ping thread started"; + } + + for(;;) + { + vector<Ice::RemoteLoggerPrx> remoteLoggers; + { + IceUtil::Monitor<IceUtil::Mutex>::Lock lock(_monitor); + if(_destroyed) + { + break; // for(;;) + } + + if(_monitor.timedWait(_pingPeriod) == false && !_destroyed) + { + transform(_remoteLoggerMap.begin(), _remoteLoggerMap.end(), back_inserter(remoteLoggers), + GetRemoteLoggerMapKey()); + } + } + + for(vector<Ice::RemoteLoggerPrx>::const_iterator p = remoteLoggers.begin(); p != remoteLoggers.end(); ++p) + { + Ice::RemoteLoggerPrx remoteLogger = (*p)->ice_twoway(); + + if(_traceLevel > 1) + { + Ice::Trace trace(logger, _facetName); + trace << "sending ice_ping to '" << remoteLogger << "'"; + } + + try + { + remoteLogger->begin_ice_ping(_remoteCallCompleted, logger); + } + catch(const Ice::LocalException& ex) + { + deadRemoteLogger(remoteLogger, logger, ex, "ice_ping"); + } + } + } + + if(_traceLevel > 1) + { + Ice::Trace trace(logger, _facetName); + trace << "Ping thread completed"; + } +} + +bool +LoggerAdminI::removeRemoteLogger(const Ice::RemoteLoggerPrx& remoteLogger) +{ + IceUtil::Monitor<IceUtil::Mutex>::Lock lock(_monitor); + return _remoteLoggerMap.erase(remoteLogger) > 0; +} + +void +LoggerAdminI::remoteCallCompleted(const Ice::AsyncResultPtr& r) +{ + try + { + r->throwLocalException(); + + if(_traceLevel > 1) + { + Ice::LoggerPtr logger = Ice::LoggerPtr::dynamicCast(r->getCookie()); + Ice::Trace trace(logger, _facetName); + trace << r->getOperation() << " on '" << r->getProxy() << "' completed successfully"; + } + } + catch(const Ice::LocalException& ex) + { + deadRemoteLogger(Ice::RemoteLoggerPrx::uncheckedCast(r->getProxy()), + Ice::LoggerPtr::dynamicCast(r->getCookie()), + ex, r->getOperation()); + } +} + +// +// PingThread +// +PingThread::PingThread( + const LoggerAdminIPtr& loggerAdmin, const Ice::LoggerPtr& logger) : + IceUtil::Thread("Ice.RemoteLoggerPingThread"), + _loggerAdmin(loggerAdmin), + _logger(logger) +{ +} + +void +PingThread::run() +{ + _loggerAdmin->run(_logger); +} + + +// +// LoggerAdminLoggerI +// + +LoggerAdminLoggerI::LoggerAdminLoggerI(const string& facetName, + const Ice::PropertiesPtr& props, + const Ice::LoggerPtr& localLogger) : + _localLogger(localLogger), + _loggerAdmin(new LoggerAdminI(facetName, props)), + _destroyed(false), + _sendLogThreadStarted(false) +{ + // + // There is currently no way to have a null local logger + // + assert(_localLogger != 0); +} + +void +LoggerAdminLoggerI::print(const string& message) +{ + Ice::LogMessage logMessage = {Ice::PrintMessage, + IceUtil::Time::now().toMicroSeconds(), + "", + message}; + + _localLogger->print(message); + log(logMessage); +} + +void +LoggerAdminLoggerI::trace(const string& category, const string& message) +{ + Ice::LogMessage logMessage = {Ice::TraceMessage, + IceUtil::Time::now().toMicroSeconds(), + category, + message}; + + _localLogger->trace(category, message); + log(logMessage); +} + +void +LoggerAdminLoggerI::warning(const string& message) +{ + Ice::LogMessage logMessage = {Ice::WarningMessage, + IceUtil::Time::now().toMicroSeconds(), + "", + message}; + + + _localLogger->warning(message); + log(logMessage); +} + +void +LoggerAdminLoggerI::error(const string& message) +{ + Ice::LogMessage logMessage = {Ice::ErrorMessage, + IceUtil::Time::now().toMicroSeconds(), + "", + message}; + + + _localLogger->error(message); + log(logMessage); +} + +string +LoggerAdminLoggerI::getPrefix() +{ + return _localLogger->getPrefix(); +} + +Ice::LoggerPtr +LoggerAdminLoggerI::cloneWithPrefix(const string& prefix) +{ + return _localLogger->cloneWithPrefix(prefix); +} + +void +LoggerAdminLoggerI::addAdminFacet(const Ice::CommunicatorPtr& communicator) +{ + communicator->addAdminFacet(_loggerAdmin, _loggerAdmin->getFacetName()); +} + +void +LoggerAdminLoggerI::log(const Ice::LogMessage& logMessage) +{ + + // + // We don't want to proceed if the SendLog thread is calling log. + // + bool proceed = false; + { + IceUtil::ThreadControl currentThread; + + IceUtil::Monitor<IceUtil::Mutex>::Lock lock(_monitor); + proceed = !_destroyed && + (!_sendLogThreadStarted || (_sendLogThreadStarted && (currentThread != _sendLogThreadControl))); + } + + if(proceed) + { + const vector<Ice::RemoteLoggerPrx> remoteLoggers = _loggerAdmin->log(logMessage); + + if(!remoteLoggers.empty()) + { + IceUtil::Monitor<IceUtil::Mutex>::Lock lock(_monitor); + + if(!_sendLogThreadStarted) + { + IceUtil::ThreadPtr t = new SendLogThread(this); + _sendLogThreadControl = t->start(); + _sendLogThreadStarted = true; + } + _jobQueue.push_back(new Job(remoteLoggers, logMessage)); + _monitor.notifyAll(); + } + } +} + +void +LoggerAdminLoggerI::destroy() +{ + _loggerAdmin->destroy(); + + IceUtil::ThreadControl sendLogThreadControl; + bool joinThread = false; + { + IceUtil::Monitor<IceUtil::Mutex>::Lock lock(_monitor); + + if(_sendLogThreadStarted) + { + joinThread = true; + sendLogThreadControl = _sendLogThreadControl; + _sendLogThreadStarted = false; + _destroyed = true; + _monitor.notifyAll(); + } + } + + if(joinThread) + { + sendLogThreadControl.join(); + } +} + +void +LoggerAdminLoggerI::run() +{ + if(_loggerAdmin->getTraceLevel() > 1) + { + Ice::Trace trace(_localLogger, _loggerAdmin->getFacetName()); + trace << "Send log thread started"; + } + + for(;;) + { + IceUtil::Monitor<IceUtil::Mutex>::Lock lock(_monitor); + while(!_destroyed && _jobQueue.empty()) + { + _monitor.wait(); + } + if(_destroyed) + { + break; // for(;;) + } + if(!_jobQueue.empty()) + { + JobPtr job = _jobQueue.front(); + _jobQueue.pop_front(); + lock.release(); + + for(vector<Ice::RemoteLoggerPrx>::const_iterator p = job->remoteLoggers.begin(); + p != job->remoteLoggers.end(); ++p) + { + if(_loggerAdmin->getTraceLevel() > 1) + { + Ice::Trace trace(_localLogger, _loggerAdmin->getFacetName()); + trace << "sending log message to '" << *p << "'"; + } + + try + { + // We use a synchronous oneway call here + // using twoway could generate additional log when receiving the response + // from the client thread-pool thread; likewise, AMI could generate + // extra logs from the client thread pool thread + + (*p)->log(job->logMessage); + } + catch(const Ice::LocalException& ex) + { + _loggerAdmin->deadRemoteLogger(*p, _localLogger, ex, "log"); + } + } + } + } + + if(_loggerAdmin->getTraceLevel() > 1) + { + Ice::Trace trace(_localLogger, _loggerAdmin->getFacetName()); + trace << "Send log thread completed"; + } +} + + +// +// SendLogThread +// + +SendLogThread::SendLogThread(const LoggerAdminLoggerIPtr& logger) : + IceUtil::Thread("Ice.SendLogThread"), + _logger(logger) +{ +} + +void +SendLogThread::run() +{ + _logger->run(); +} +} + +// +// createLoggerAdminLogger +// + +namespace IceInternal +{ + +Ice::LoggerAdminLoggerPtr +createLoggerAdminLogger(const std::string& facetName, + const Ice::PropertiesPtr& props, + const Ice::LoggerPtr& localLogger) +{ + return new LoggerAdminLoggerI(facetName, props, localLogger); +} + +} diff --git a/cpp/src/Ice/LoggerAdminI.h b/cpp/src/Ice/LoggerAdminI.h new file mode 100644 index 00000000000..1a175d1b8ff --- /dev/null +++ b/cpp/src/Ice/LoggerAdminI.h @@ -0,0 +1,53 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef ICE_LOGGER_ADMIN_I_H +#define ICE_LOGGER_ADMIN_I_H + +#include <Ice/Config.h> +#include <Ice/Logger.h> +#include <Ice/PropertiesF.h> +#include <Ice/CommunicatorF.h> + +namespace Ice +{ + +// +// A logger that works in tandem with a "Logger" admin facet. +// +class ICE_API LoggerAdminLogger : public Ice::Logger +{ +public: + + // + // Add the associated LoggerAdmin facet to this communicator + // + virtual void addAdminFacet(const CommunicatorPtr&) = 0; + + + // + // Destroy this logger, in particular join any thread + // that this logger may have started + // + virtual void destroy() = 0; + +}; +typedef IceInternal::Handle<LoggerAdminLogger> LoggerAdminLoggerPtr; + +} + +namespace IceInternal +{ + +Ice::LoggerAdminLoggerPtr +createLoggerAdminLogger(const std::string&, const Ice::PropertiesPtr&, const Ice::LoggerPtr&); + +} + +#endif diff --git a/cpp/src/Ice/LoggerI.cpp b/cpp/src/Ice/LoggerI.cpp index 430d9fd49f6..e3298062478 100644 --- a/cpp/src/Ice/LoggerI.cpp +++ b/cpp/src/Ice/LoggerI.cpp @@ -50,6 +50,7 @@ Init init; Ice::LoggerI::LoggerI(const string& prefix, const string& file, bool convert, const IceUtil::StringConverterPtr& converter) : + _prefix(prefix), _convert(convert), _converter(converter) #if defined(_WIN32) && !defined(ICE_OS_WINRT) @@ -59,7 +60,7 @@ Ice::LoggerI::LoggerI(const string& prefix, const string& file, { if(!prefix.empty()) { - _prefix = prefix + ": "; + _formattedPrefix = prefix + ": "; } if(!file.empty()) @@ -90,7 +91,7 @@ Ice::LoggerI::print(const string& message) void Ice::LoggerI::trace(const string& category, const string& message) { - string s = "-- " + IceUtil::Time::now().toDateTime() + " " + _prefix; + string s = "-- " + IceUtil::Time::now().toDateTime() + " " + _formattedPrefix; if(!category.empty()) { s += category + ": "; @@ -103,13 +104,19 @@ Ice::LoggerI::trace(const string& category, const string& message) void Ice::LoggerI::warning(const string& message) { - write("-! " + IceUtil::Time::now().toDateTime() + " " + _prefix + "warning: " + message, true); + write("-! " + IceUtil::Time::now().toDateTime() + " " + _formattedPrefix + "warning: " + message, true); } void Ice::LoggerI::error(const string& message) { - write("!! " + IceUtil::Time::now().toDateTime() + " " + _prefix + "error: " + message, true); + write("!! " + IceUtil::Time::now().toDateTime() + " " + _formattedPrefix + "error: " + message, true); +} + +string +Ice::LoggerI::getPrefix() +{ + return _prefix; } LoggerPtr diff --git a/cpp/src/Ice/LoggerI.h b/cpp/src/Ice/LoggerI.h index 1ae72c9445b..f8fbb813252 100644 --- a/cpp/src/Ice/LoggerI.h +++ b/cpp/src/Ice/LoggerI.h @@ -29,13 +29,15 @@ public: virtual void trace(const std::string&, const std::string&); virtual void warning(const std::string&); virtual void error(const std::string&); + virtual std::string getPrefix(); virtual LoggerPtr cloneWithPrefix(const std::string&); private: void write(const std::string&, bool); - std::string _prefix; + const std::string _prefix; + std::string _formattedPrefix; const bool _convert; const IceUtil::StringConverterPtr _converter; IceUtilInternal::ofstream _out; diff --git a/cpp/src/Ice/Makefile b/cpp/src/Ice/Makefile index 7fa44656c04..7c5803c1a96 100644 --- a/cpp/src/Ice/Makefile +++ b/cpp/src/Ice/Makefile @@ -58,8 +58,9 @@ OBJS = Acceptor.o \ LocalObject.o \ LocatorInfo.o \ Locator.o \ - LoggerI.o \ Logger.o \ + LoggerAdminI.o \ + LoggerI.o \ LoggerUtil.o \ Metrics.o \ MetricsAdminI.o \ @@ -92,6 +93,7 @@ OBJS = Acceptor.o \ Proxy.o \ ReferenceFactory.o \ Reference.o \ + RemoteLogger.o \ ResponseHandler.o \ RetryQueue.o \ RequestHandler.o \ diff --git a/cpp/src/Ice/Makefile.mak b/cpp/src/Ice/Makefile.mak index 85c8a06a7ab..2d847dce230 100644 --- a/cpp/src/Ice/Makefile.mak +++ b/cpp/src/Ice/Makefile.mak @@ -59,6 +59,7 @@ OBJS = Acceptor.obj \ LocalObject.obj \ LocatorInfo.obj \ Locator.obj \ + LoggerAdminI.obj \ LoggerI.obj \ Logger.obj \ LoggerUtil.obj \ @@ -93,6 +94,7 @@ OBJS = Acceptor.obj \ Proxy.obj \ ReferenceFactory.obj \ Reference.obj \ + RemoteLogger.obj \ RetryQueue.obj \ RequestHandler.obj \ ResponseHandler.obj \ @@ -195,6 +197,7 @@ clean:: -del /q PropertiesF.cpp $(HDIR)\PropertiesF.h -del /q PropertiesAdmin.cpp $(HDIR)\PropertiesAdmin.h -del /q Properties.cpp $(HDIR)\Properties.h + -del /q RemoteLogger.cpp $(HDIR)\RemoteLogger.h -del /q RouterF.cpp $(HDIR)\RouterF.h -del /q Router.cpp $(HDIR)\Router.h -del /q ServantLocatorF.cpp $(HDIR)\ServantLocatorF.h diff --git a/cpp/src/Ice/PropertyNames.cpp b/cpp/src/Ice/PropertyNames.cpp index 7c11a5db27b..92ecdaddc56 100644 --- a/cpp/src/Ice/PropertyNames.cpp +++ b/cpp/src/Ice/PropertyNames.cpp @@ -6,7 +6,7 @@ // ICE_LICENSE file included in this distribution. // // ********************************************************************** -// Generated by makeprops.py from file ./config/PropertyNames.xml, Wed Aug 13 15:11:58 2014 +// Generated by makeprops.py from file ../config/PropertyNames.xml, Thu Aug 14 14:50:07 2014 // IMPORTANT: Do not edit this file -- any edits made here will be lost! @@ -67,6 +67,9 @@ const IceInternal::Property IcePropsData[] = IceInternal::Property("Ice.Admin.DelayCreation", false, 0), IceInternal::Property("Ice.Admin.Facets", false, 0), IceInternal::Property("Ice.Admin.InstanceName", false, 0), + IceInternal::Property("Ice.Admin.Logger.KeepLogs", false, 0), + IceInternal::Property("Ice.Admin.Logger.KeepTraces", false, 0), + IceInternal::Property("Ice.Admin.Logger.PingPeriod", false, 0), IceInternal::Property("Ice.Admin.ServerId", false, 0), IceInternal::Property("Ice.BackgroundLocatorCacheUpdates", false, 0), IceInternal::Property("Ice.BatchAutoFlush", false, 0), @@ -156,6 +159,7 @@ const IceInternal::Property IcePropsData[] = IceInternal::Property("Ice.ThreadPool.Server.ThreadPriority", false, 0), IceInternal::Property("Ice.ThreadPriority", false, 0), IceInternal::Property("Ice.Trace.Admin.Properties", false, 0), + IceInternal::Property("Ice.Trace.Admin.Logger", false, 0), IceInternal::Property("Ice.Trace.Locator", false, 0), IceInternal::Property("Ice.Trace.Network", false, 0), IceInternal::Property("Ice.Trace.Protocol", false, 0), diff --git a/cpp/src/Ice/PropertyNames.h b/cpp/src/Ice/PropertyNames.h index d5b33df89b8..6a38fafc5e3 100644 --- a/cpp/src/Ice/PropertyNames.h +++ b/cpp/src/Ice/PropertyNames.h @@ -6,7 +6,7 @@ // ICE_LICENSE file included in this distribution. // // ********************************************************************** -// Generated by makeprops.py from file ./config/PropertyNames.xml, Wed Aug 13 15:11:58 2014 +// Generated by makeprops.py from file ../config/PropertyNames.xml, Thu Aug 14 14:50:07 2014 // IMPORTANT: Do not edit this file -- any edits made here will be lost! diff --git a/cpp/src/Ice/ProtocolInstance.cpp b/cpp/src/Ice/ProtocolInstance.cpp index 363de0cb1b0..2c27bb2c0c2 100644 --- a/cpp/src/Ice/ProtocolInstance.cpp +++ b/cpp/src/Ice/ProtocolInstance.cpp @@ -24,7 +24,6 @@ IceInternal::ProtocolInstance::ProtocolInstance(const CommunicatorPtr& com, Shor _instance(getInstance(com)), _traceLevel(_instance->traceLevels()->network), _traceCategory(_instance->traceLevels()->networkCat), - _logger(_instance->initializationData().logger), _properties(_instance->initializationData().properties), _protocol(protocol), _type(type) @@ -35,7 +34,6 @@ IceInternal::ProtocolInstance::ProtocolInstance(const InstancePtr& instance, Sho _instance(instance), _traceLevel(_instance->traceLevels()->network), _traceCategory(_instance->traceLevels()->networkCat), - _logger(_instance->initializationData().logger), _properties(_instance->initializationData().properties), _protocol(protocol), _type(type) diff --git a/cpp/src/Ice/ProtocolInstance.h b/cpp/src/Ice/ProtocolInstance.h index 9a0ebec59b9..60ce51426f2 100644 --- a/cpp/src/Ice/ProtocolInstance.h +++ b/cpp/src/Ice/ProtocolInstance.h @@ -18,6 +18,7 @@ #include <Ice/ConnectorF.h> #include <Ice/IPEndpointIF.h> #include <Ice/NetworkF.h> +#include <Ice/Instance.h> namespace IceInternal { @@ -40,7 +41,7 @@ public: const Ice::LoggerPtr& logger() const { - return _logger; + return _instance->initializationData().logger; } const std::string& protocol() const @@ -81,7 +82,6 @@ protected: const int _traceLevel; const std::string _traceCategory; - const Ice::LoggerPtr _logger; const Ice::PropertiesPtr _properties; const std::string _protocol; const Ice::Short _type; diff --git a/cpp/src/Ice/Service.cpp b/cpp/src/Ice/Service.cpp index 4fca9da3e36..f3271be7cb8 100644 --- a/cpp/src/Ice/Service.cpp +++ b/cpp/src/Ice/Service.cpp @@ -187,6 +187,12 @@ public: _logger->error(_prefix, message); } + virtual string + getPrefix() + { + return _prefix; + } + virtual Ice::LoggerPtr cloneWithPrefix(const string& prefix) { @@ -196,10 +202,10 @@ public: private: SMEventLoggerPtr _logger; - string _prefix; + const string _prefix; }; -class SMEventLoggerI : public Ice::Logger, public SMEventLogger +class SMEventLoggerI : public SMEventLogger { public: @@ -317,14 +323,14 @@ public: print(s); } - virtual void + void print(const string& message) { // // Don't need to use a wide string converter as the wide string is passed // to Windows API. // - wstring msg = IceUtil::stringToWstring(message, _stringConverter); + wstring msg = IceUtil::stringToWstring(message, _stringConverter); const wchar_t* messages[1]; messages[0] = msg.c_str(); // @@ -347,7 +353,7 @@ public: trace(prefix, s); } - virtual void + void trace(const string& category, const string& message) { string s; @@ -362,7 +368,7 @@ public: // Don't need to use a wide string converter as the wide string is passed // to Windows API. // - wstring msg = IceUtil::stringToWstring(s, _stringConverter); + wstring msg = IceUtil::stringToWstring(s, _stringConverter); const wchar_t* messages[1]; messages[0] = msg.c_str(); // @@ -385,14 +391,14 @@ public: warning(s); } - virtual void + void warning(const string& message) { // // Don't need to use a wide string converter as the wide string is passed // to Windows API. // - wstring msg = IceUtil::stringToWstring(message, _stringConverter); + wstring msg = IceUtil::stringToWstring(message, _stringConverter); const wchar_t* messages[1]; messages[0] = msg.c_str(); // @@ -415,14 +421,14 @@ public: error(s); } - virtual void + void error(const string& message) { // // Don't need to use a wide string converter as the wide string is passed // to Windows API. // - wstring msg = IceUtil::stringToWstring(message, _stringConverter); + wstring msg = IceUtil::stringToWstring(message, _stringConverter); const wchar_t* messages[1]; messages[0] = msg.c_str(); // @@ -432,12 +438,6 @@ public: ReportEventW(_source, EVENTLOG_ERROR_TYPE, 0, EVENT_LOGGER_MSG, 0, 1, 0, messages, 0); } - virtual Ice::LoggerPtr - cloneWithPrefix(const string& prefix) - { - return new SMEventLoggerIWrapper(this, prefix); - } - static void setModuleHandle(HMODULE module) { diff --git a/cpp/src/Ice/SysLoggerI.cpp b/cpp/src/Ice/SysLoggerI.cpp index 65a35ddecc5..197e88ae375 100644 --- a/cpp/src/Ice/SysLoggerI.cpp +++ b/cpp/src/Ice/SysLoggerI.cpp @@ -15,7 +15,9 @@ using namespace std; using namespace Ice; using namespace IceInternal; -Ice::SysLoggerI::SysLoggerI(const string& prefix, const string& facilityString) +Ice::SysLoggerI::SysLoggerI(const string& prefix, const string& facilityString) : + _facility(0), + _prefix(prefix) { if(facilityString == "LOG_KERN") { @@ -111,7 +113,8 @@ Ice::SysLoggerI::SysLoggerI(const string& prefix, const string& facilityString) } Ice::SysLoggerI::SysLoggerI(const string& prefix, int facility) : - _facility(facility) + _facility(facility), + _prefix(prefix) { int logopt = LOG_PID | LOG_CONS; openlog(prefix.c_str(), logopt, facility); @@ -151,6 +154,12 @@ Ice::SysLoggerI::error(const string& message) syslog(LOG_ERR, "%s", message.c_str()); } +string +Ice::SysLoggerI::getPrefix() +{ + return _prefix; +} + Ice::LoggerPtr Ice::SysLoggerI::cloneWithPrefix(const string& prefix) { diff --git a/cpp/src/Ice/SysLoggerI.h b/cpp/src/Ice/SysLoggerI.h index c493f5179d9..e141c7b2bc0 100644 --- a/cpp/src/Ice/SysLoggerI.h +++ b/cpp/src/Ice/SysLoggerI.h @@ -27,6 +27,7 @@ public: virtual void trace(const std::string&, const std::string&); virtual void warning(const std::string&); virtual void error(const std::string&); + virtual std::string getPrefix(); virtual LoggerPtr cloneWithPrefix(const std::string&); private: @@ -34,6 +35,7 @@ private: SysLoggerI(const std::string&, int); int _facility; + const std::string _prefix; }; } diff --git a/cpp/src/IceBox/ServiceManagerI.cpp b/cpp/src/IceBox/ServiceManagerI.cpp index d1883c77537..433985d971a 100644 --- a/cpp/src/IceBox/ServiceManagerI.cpp +++ b/cpp/src/IceBox/ServiceManagerI.cpp @@ -17,6 +17,7 @@ #include <Ice/PropertiesAdminI.h> #include <Ice/MetricsAdminI.h> #include <Ice/InstrumentationI.h> +#include <Ice/LoggerAdminI.h> #include <IceBox/ServiceManagerI.h> using namespace Ice; @@ -597,6 +598,10 @@ IceBox::ServiceManagerI::start(const string& service, const string& entryPoint, #endif ) { + // + // When _logger is a LoggerAdminLogger, cloneWithPrefix returns a clone of the + // underlying local logger, not of the LoggerAdminLogger itself + // initData.logger = _logger->cloneWithPrefix(initData.properties->getProperty("Ice.ProgramName")); } @@ -611,12 +616,38 @@ IceBox::ServiceManagerI::start(const string& service, const string& entryPoint, } // + // If the Logger is enabled on the IceBox communicator, we tell the service + // to create a LoggerAdmin's Logger, by setting the property Ice.Admin.Logger + // + if(_communicator->findAdminFacet("Logger") != 0) + { + if(initData.properties->getPropertyWithDefault("Ice.Admin.Logger", "Logger") == "Logger") + { + initData.properties->setProperty("Ice.Admin.Logger", string("IceBox.Service.") + service + ".Logger"); + } + } + + // // Remaining command line options are passed to the communicator. This is // necessary for Ice plug-in properties (e.g.: IceSSL). // info.communicator = initialize(info.args, initData); communicator = info.communicator; + if(_communicator->findAdminFacet("Logger") != 0) + { + Ice::LoggerAdminLoggerPtr logger = Ice::LoggerAdminLoggerPtr::dynamicCast(communicator->getLogger()); + assert(logger != 0); // a plugin reset Ice.Admin.Logger to its default?? + if(logger != 0) + { + // + // We add this admin facet to the IceBox main communicator, even though the associated logger + // "works" for the service's communicator + // + logger->addAdminFacet(_communicator); + } + } + // // Ensure the metrics admin plugin uses the same property set as the // communicator. This is necessary to correctly deal with runtime diff --git a/cpp/src/IceGrid/Grammar.cpp b/cpp/src/IceGrid/Grammar.cpp index 129718be7b9..df811692aa3 100644 --- a/cpp/src/IceGrid/Grammar.cpp +++ b/cpp/src/IceGrid/Grammar.cpp @@ -1,10 +1,9 @@ - -/* A Bison parser, made by GNU Bison 2.4.1. */ +/* A Bison parser, made by GNU Bison 2.4.2. */ /* Skeleton implementation for Bison's Yacc-like parsers in C - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 - Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2006, 2009-2010 Free Software + Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -46,7 +45,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.4.1" +#define YYBISON_VERSION "2.4.2" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -104,7 +103,7 @@ yyerror(const char* s) /* Line 189 of yacc.c */ -#line 108 "Grammar.tab.c" +#line 107 "Grammar.tab.c" /* Enabling traces. */ #ifndef YYDEBUG @@ -188,7 +187,7 @@ typedef int YYSTYPE; /* Line 264 of yacc.c */ -#line 192 "Grammar.tab.c" +#line 191 "Grammar.tab.c" #ifdef short # undef short @@ -238,7 +237,7 @@ typedef short int yytype_int16; #define YYSIZE_MAXIMUM ((YYSIZE_T) -1) #ifndef YY_ -# if YYENABLE_NLS +# if defined YYENABLE_NLS && YYENABLE_NLS # if ENABLE_NLS # include <libintl.h> /* INFRINGES ON USER NAME SPACE */ # define YY_(msgid) dgettext ("bison-runtime", msgid) @@ -1355,9 +1354,18 @@ static const yytype_uint8 yystos[] = /* Like YYERROR except do call yyerror. This remains here temporarily to ease the transition to the new meaning of YYERROR, for GCC. - Once GCC version 2 has supplanted version 1, this can go. */ + Once GCC version 2 has supplanted version 1, this can go. However, + YYFAIL appears to be in use. Nevertheless, it is formally deprecated + in Bison 2.4.2's NEWS entry, where a plan to phase it out is + discussed. */ #define YYFAIL goto yyerrlab +#if defined YYFAIL + /* This is here to suppress warnings from the GCC cpp's + -Wunused-macros. Normally we don't worry about that warning, but + some users do, and we want to make it easy for users to remove + YYFAIL uses, which will produce warnings from Bison 2.5. */ +#endif #define YYRECOVERING() (!!yyerrstatus) @@ -1414,7 +1422,7 @@ while (YYID (0)) we won't break user code: when these are the locations we know. */ #ifndef YY_LOCATION_PRINT -# if YYLTYPE_IS_TRIVIAL +# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL # define YY_LOCATION_PRINT(File, Loc) \ fprintf (File, "%d.%d-%d.%d", \ (Loc).first_line, (Loc).first_column, \ @@ -2152,7 +2160,7 @@ yyreduce: { case 2: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 89 "Grammar.y" { ;} @@ -2160,7 +2168,7 @@ yyreduce: case 3: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 92 "Grammar.y" { ;} @@ -2168,7 +2176,7 @@ yyreduce: case 4: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 100 "Grammar.y" { ;} @@ -2176,7 +2184,7 @@ yyreduce: case 5: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 103 "Grammar.y" { ;} @@ -2184,7 +2192,7 @@ yyreduce: case 6: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 109 "Grammar.y" { parser->checkInterrupted(); @@ -2193,7 +2201,7 @@ yyreduce: case 7: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 118 "Grammar.y" { parser->usage(); @@ -2202,7 +2210,7 @@ yyreduce: case 8: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 122 "Grammar.y" { return 0; @@ -2211,7 +2219,7 @@ yyreduce: case 9: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 126 "Grammar.y" { parser->addApplication((yyvsp[(3) - (4)])); @@ -2220,7 +2228,7 @@ yyreduce: case 10: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 130 "Grammar.y" { parser->usage("application", "add"); @@ -2229,7 +2237,7 @@ yyreduce: case 11: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 134 "Grammar.y" { parser->removeApplication((yyvsp[(3) - (4)])); @@ -2238,7 +2246,7 @@ yyreduce: case 12: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 138 "Grammar.y" { parser->usage("application", "remove"); @@ -2247,7 +2255,7 @@ yyreduce: case 13: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 142 "Grammar.y" { parser->diffApplication((yyvsp[(3) - (4)])); @@ -2256,7 +2264,7 @@ yyreduce: case 14: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 146 "Grammar.y" { parser->usage("application", "diff"); @@ -2265,7 +2273,7 @@ yyreduce: case 15: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 150 "Grammar.y" { parser->updateApplication((yyvsp[(3) - (4)])); @@ -2274,7 +2282,7 @@ yyreduce: case 16: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 154 "Grammar.y" { parser->usage("application", "update"); @@ -2283,7 +2291,7 @@ yyreduce: case 17: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 158 "Grammar.y" { parser->describeApplication((yyvsp[(3) - (4)])); @@ -2292,7 +2300,7 @@ yyreduce: case 18: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 162 "Grammar.y" { parser->usage("application", "describe"); @@ -2301,7 +2309,7 @@ yyreduce: case 19: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 166 "Grammar.y" { parser->patchApplication((yyvsp[(3) - (4)])); @@ -2310,7 +2318,7 @@ yyreduce: case 20: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 170 "Grammar.y" { parser->usage("application", "patch"); @@ -2319,7 +2327,7 @@ yyreduce: case 21: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 174 "Grammar.y" { parser->listAllApplications((yyvsp[(3) - (4)])); @@ -2328,7 +2336,7 @@ yyreduce: case 22: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 178 "Grammar.y" { parser->usage("application", "list"); @@ -2337,7 +2345,7 @@ yyreduce: case 23: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 182 "Grammar.y" { parser->describeServerTemplate((yyvsp[(4) - (5)])); @@ -2346,7 +2354,7 @@ yyreduce: case 24: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 186 "Grammar.y" { parser->usage("server template", "describe"); @@ -2355,7 +2363,7 @@ yyreduce: case 25: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 190 "Grammar.y" { parser->instantiateServerTemplate((yyvsp[(4) - (5)])); @@ -2364,7 +2372,7 @@ yyreduce: case 26: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 194 "Grammar.y" { parser->usage("server template", "instantiate"); @@ -2373,7 +2381,7 @@ yyreduce: case 27: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 198 "Grammar.y" { parser->usage("server template"); @@ -2382,7 +2390,7 @@ yyreduce: case 28: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 202 "Grammar.y" { parser->describeServiceTemplate((yyvsp[(4) - (5)])); @@ -2391,7 +2399,7 @@ yyreduce: case 29: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 206 "Grammar.y" { parser->usage("service template", "describe"); @@ -2400,7 +2408,7 @@ yyreduce: case 30: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 210 "Grammar.y" { parser->usage("service template"); @@ -2409,7 +2417,7 @@ yyreduce: case 31: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 214 "Grammar.y" { parser->describeNode((yyvsp[(3) - (4)])); @@ -2418,7 +2426,7 @@ yyreduce: case 32: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 218 "Grammar.y" { parser->usage("node", "describe"); @@ -2427,7 +2435,7 @@ yyreduce: case 33: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 222 "Grammar.y" { parser->pingNode((yyvsp[(3) - (4)])); @@ -2436,7 +2444,7 @@ yyreduce: case 34: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 226 "Grammar.y" { parser->usage("node", "ping"); @@ -2445,7 +2453,7 @@ yyreduce: case 35: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 230 "Grammar.y" { parser->printLoadNode((yyvsp[(3) - (4)])); @@ -2454,7 +2462,7 @@ yyreduce: case 36: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 234 "Grammar.y" { parser->usage("node", "load"); @@ -2463,7 +2471,7 @@ yyreduce: case 37: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 238 "Grammar.y" { parser->printNodeProcessorSockets((yyvsp[(3) - (4)])); @@ -2472,7 +2480,7 @@ yyreduce: case 38: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 242 "Grammar.y" { parser->usage("node", "sockets"); @@ -2481,7 +2489,7 @@ yyreduce: case 39: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 246 "Grammar.y" { parser->shutdownNode((yyvsp[(3) - (4)])); @@ -2490,7 +2498,7 @@ yyreduce: case 40: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 250 "Grammar.y" { parser->usage("node", "shutdown"); @@ -2499,7 +2507,7 @@ yyreduce: case 41: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 254 "Grammar.y" { parser->listAllNodes((yyvsp[(3) - (4)])); @@ -2508,7 +2516,7 @@ yyreduce: case 42: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 258 "Grammar.y" { parser->usage("node", "list"); @@ -2517,16 +2525,16 @@ yyreduce: case 43: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 262 "Grammar.y" { - parser->showFile("node", (yyvsp[(3) - (4)])); + parser->show("node", (yyvsp[(3) - (4)])); ;} break; case 44: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 266 "Grammar.y" { parser->usage("node", "show"); @@ -2535,7 +2543,7 @@ yyreduce: case 45: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 270 "Grammar.y" { parser->describeRegistry((yyvsp[(3) - (4)])); @@ -2544,7 +2552,7 @@ yyreduce: case 46: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 274 "Grammar.y" { parser->usage("registry", "describe"); @@ -2553,7 +2561,7 @@ yyreduce: case 47: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 278 "Grammar.y" { parser->pingRegistry((yyvsp[(3) - (4)])); @@ -2562,7 +2570,7 @@ yyreduce: case 48: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 282 "Grammar.y" { parser->usage("registry", "ping"); @@ -2571,7 +2579,7 @@ yyreduce: case 49: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 286 "Grammar.y" { parser->shutdownRegistry((yyvsp[(3) - (4)])); @@ -2580,7 +2588,7 @@ yyreduce: case 50: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 290 "Grammar.y" { parser->usage("registry", "shutdown"); @@ -2589,7 +2597,7 @@ yyreduce: case 51: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 294 "Grammar.y" { parser->listAllRegistries((yyvsp[(3) - (4)])); @@ -2598,7 +2606,7 @@ yyreduce: case 52: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 298 "Grammar.y" { parser->usage("registry", "list"); @@ -2607,16 +2615,16 @@ yyreduce: case 53: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 302 "Grammar.y" { - parser->showFile("registry", (yyvsp[(3) - (4)])); + parser->show("registry", (yyvsp[(3) - (4)])); ;} break; case 54: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 306 "Grammar.y" { parser->usage("registry", "show"); @@ -2625,7 +2633,7 @@ yyreduce: case 55: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 310 "Grammar.y" { parser->removeServer((yyvsp[(3) - (4)])); @@ -2634,7 +2642,7 @@ yyreduce: case 56: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 314 "Grammar.y" { parser->usage("server", "remove"); @@ -2643,7 +2651,7 @@ yyreduce: case 57: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 318 "Grammar.y" { parser->describeServer((yyvsp[(3) - (4)])); @@ -2652,7 +2660,7 @@ yyreduce: case 58: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 322 "Grammar.y" { parser->usage("server", "describe"); @@ -2661,7 +2669,7 @@ yyreduce: case 59: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 326 "Grammar.y" { parser->startServer((yyvsp[(3) - (4)])); @@ -2670,7 +2678,7 @@ yyreduce: case 60: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 330 "Grammar.y" { parser->usage("server", "start"); @@ -2679,7 +2687,7 @@ yyreduce: case 61: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 334 "Grammar.y" { parser->stopServer((yyvsp[(3) - (4)])); @@ -2688,7 +2696,7 @@ yyreduce: case 62: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 338 "Grammar.y" { parser->usage("server", "stop"); @@ -2697,7 +2705,7 @@ yyreduce: case 63: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 342 "Grammar.y" { parser->patchServer((yyvsp[(3) - (4)])); @@ -2706,7 +2714,7 @@ yyreduce: case 64: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 346 "Grammar.y" { parser->usage("server", "patch"); @@ -2715,7 +2723,7 @@ yyreduce: case 65: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 350 "Grammar.y" { parser->signalServer((yyvsp[(3) - (4)])); @@ -2724,7 +2732,7 @@ yyreduce: case 66: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 354 "Grammar.y" { parser->usage("server", "signal"); @@ -2733,7 +2741,7 @@ yyreduce: case 67: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 358 "Grammar.y" { parser->writeMessage((yyvsp[(3) - (4)]), 1); @@ -2742,7 +2750,7 @@ yyreduce: case 68: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 362 "Grammar.y" { parser->usage("server", "stdout"); @@ -2751,7 +2759,7 @@ yyreduce: case 69: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 366 "Grammar.y" { parser->writeMessage((yyvsp[(3) - (4)]), 2); @@ -2760,7 +2768,7 @@ yyreduce: case 70: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 370 "Grammar.y" { parser->usage("server", "stderr"); @@ -2769,7 +2777,7 @@ yyreduce: case 71: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 374 "Grammar.y" { parser->stateServer((yyvsp[(3) - (4)])); @@ -2778,7 +2786,7 @@ yyreduce: case 72: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 378 "Grammar.y" { parser->usage("server", "start"); @@ -2787,7 +2795,7 @@ yyreduce: case 73: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 382 "Grammar.y" { parser->pidServer((yyvsp[(3) - (4)])); @@ -2796,7 +2804,7 @@ yyreduce: case 74: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 386 "Grammar.y" { parser->usage("server", "pid"); @@ -2805,7 +2813,7 @@ yyreduce: case 75: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 390 "Grammar.y" { parser->propertiesServer((yyvsp[(3) - (4)]), false); @@ -2814,7 +2822,7 @@ yyreduce: case 76: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 394 "Grammar.y" { parser->usage("server", "properties"); @@ -2823,7 +2831,7 @@ yyreduce: case 77: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 398 "Grammar.y" { parser->propertiesServer((yyvsp[(3) - (4)]), true); @@ -2832,7 +2840,7 @@ yyreduce: case 78: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 402 "Grammar.y" { parser->usage("server", "property"); @@ -2841,7 +2849,7 @@ yyreduce: case 79: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 406 "Grammar.y" { parser->enableServer((yyvsp[(3) - (4)]), true); @@ -2850,7 +2858,7 @@ yyreduce: case 80: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 410 "Grammar.y" { parser->usage("server", "enable"); @@ -2859,7 +2867,7 @@ yyreduce: case 81: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 414 "Grammar.y" { parser->enableServer((yyvsp[(3) - (4)]), false); @@ -2868,7 +2876,7 @@ yyreduce: case 82: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 418 "Grammar.y" { parser->usage("server", "disable"); @@ -2877,7 +2885,7 @@ yyreduce: case 83: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 422 "Grammar.y" { parser->listAllServers((yyvsp[(3) - (4)])); @@ -2886,7 +2894,7 @@ yyreduce: case 84: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 426 "Grammar.y" { parser->usage("server", "list"); @@ -2895,16 +2903,16 @@ yyreduce: case 85: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 430 "Grammar.y" { - parser->showFile("server", (yyvsp[(3) - (4)])); + parser->show("server", (yyvsp[(3) - (4)])); ;} break; case 86: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 434 "Grammar.y" { parser->usage("server", "show"); @@ -2913,7 +2921,7 @@ yyreduce: case 87: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 438 "Grammar.y" { parser->startService((yyvsp[(3) - (4)])); @@ -2922,7 +2930,7 @@ yyreduce: case 88: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 442 "Grammar.y" { parser->usage("service", "start"); @@ -2931,7 +2939,7 @@ yyreduce: case 89: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 446 "Grammar.y" { parser->stopService((yyvsp[(3) - (4)])); @@ -2940,7 +2948,7 @@ yyreduce: case 90: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 450 "Grammar.y" { parser->usage("service", "stop"); @@ -2949,7 +2957,7 @@ yyreduce: case 91: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 454 "Grammar.y" { parser->describeService((yyvsp[(3) - (4)])); @@ -2958,7 +2966,7 @@ yyreduce: case 92: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 458 "Grammar.y" { parser->usage("service", "describe"); @@ -2967,7 +2975,7 @@ yyreduce: case 93: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 462 "Grammar.y" { parser->propertiesService((yyvsp[(3) - (4)]), false); @@ -2976,7 +2984,7 @@ yyreduce: case 94: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 466 "Grammar.y" { parser->usage("service", "properties"); @@ -2985,7 +2993,7 @@ yyreduce: case 95: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 470 "Grammar.y" { parser->propertiesService((yyvsp[(3) - (4)]), true); @@ -2994,7 +3002,7 @@ yyreduce: case 96: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 474 "Grammar.y" { parser->usage("service", "property"); @@ -3003,7 +3011,7 @@ yyreduce: case 97: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 478 "Grammar.y" { parser->listServices((yyvsp[(3) - (4)])); @@ -3012,7 +3020,7 @@ yyreduce: case 98: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 482 "Grammar.y" { parser->usage("service", "list"); @@ -3021,7 +3029,7 @@ yyreduce: case 99: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 486 "Grammar.y" { parser->endpointsAdapter((yyvsp[(3) - (4)])); @@ -3030,7 +3038,7 @@ yyreduce: case 100: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 490 "Grammar.y" { parser->usage("adapter", "endpoints"); @@ -3039,7 +3047,7 @@ yyreduce: case 101: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 494 "Grammar.y" { parser->removeAdapter((yyvsp[(3) - (4)])); @@ -3048,7 +3056,7 @@ yyreduce: case 102: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 498 "Grammar.y" { parser->usage("adapter", "remove"); @@ -3057,7 +3065,7 @@ yyreduce: case 103: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 502 "Grammar.y" { parser->listAllAdapters((yyvsp[(3) - (4)])); @@ -3066,7 +3074,7 @@ yyreduce: case 104: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 506 "Grammar.y" { parser->usage("adapter", "list"); @@ -3075,7 +3083,7 @@ yyreduce: case 105: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 510 "Grammar.y" { parser->addObject((yyvsp[(3) - (4)])); @@ -3084,7 +3092,7 @@ yyreduce: case 106: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 514 "Grammar.y" { parser->usage("object", "add"); @@ -3093,7 +3101,7 @@ yyreduce: case 107: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 518 "Grammar.y" { parser->removeObject((yyvsp[(3) - (4)])); @@ -3102,7 +3110,7 @@ yyreduce: case 108: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 522 "Grammar.y" { parser->usage("object", "remove"); @@ -3111,7 +3119,7 @@ yyreduce: case 109: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 526 "Grammar.y" { parser->findObject((yyvsp[(3) - (4)])); @@ -3120,7 +3128,7 @@ yyreduce: case 110: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 530 "Grammar.y" { parser->usage("object", "find"); @@ -3129,7 +3137,7 @@ yyreduce: case 111: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 534 "Grammar.y" { parser->listObject((yyvsp[(3) - (4)])); @@ -3138,7 +3146,7 @@ yyreduce: case 112: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 538 "Grammar.y" { parser->usage("object", "list"); @@ -3147,7 +3155,7 @@ yyreduce: case 113: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 542 "Grammar.y" { parser->describeObject((yyvsp[(3) - (4)])); @@ -3156,7 +3164,7 @@ yyreduce: case 114: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 546 "Grammar.y" { parser->usage("object", "describe"); @@ -3165,7 +3173,7 @@ yyreduce: case 115: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 550 "Grammar.y" { parser->showCopying(); @@ -3174,7 +3182,7 @@ yyreduce: case 116: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 554 "Grammar.y" { parser->showWarranty(); @@ -3183,7 +3191,7 @@ yyreduce: case 117: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 558 "Grammar.y" { parser->usage((yyvsp[(2) - (3)]).front()); @@ -3192,7 +3200,7 @@ yyreduce: case 118: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 562 "Grammar.y" { if(((yyvsp[(2) - (4)]).front() == "server" || (yyvsp[(2) - (4)]).front() == "service") && (yyvsp[(3) - (4)]).front() == "template") @@ -3208,7 +3216,7 @@ yyreduce: case 119: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 573 "Grammar.y" { parser->usage((yyvsp[(2) - (5)]).front(), (yyvsp[(3) - (5)]).front()); @@ -3217,7 +3225,7 @@ yyreduce: case 120: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 577 "Grammar.y" { if(((yyvsp[(2) - (5)]).front() == "server" || (yyvsp[(2) - (5)]).front() == "service") && (yyvsp[(3) - (5)]).front() == "template") @@ -3233,7 +3241,7 @@ yyreduce: case 121: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 588 "Grammar.y" { if(((yyvsp[(2) - (6)]).front() == "server" || (yyvsp[(2) - (6)]).front() == "service") && (yyvsp[(3) - (6)]).front() == "template") @@ -3249,7 +3257,7 @@ yyreduce: case 122: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 599 "Grammar.y" { parser->usage((yyvsp[(2) - (4)]).front()); @@ -3258,7 +3266,7 @@ yyreduce: case 123: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 603 "Grammar.y" { parser->usage(); @@ -3267,7 +3275,7 @@ yyreduce: case 124: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 607 "Grammar.y" { parser->usage((yyvsp[(1) - (3)]).front()); @@ -3276,7 +3284,7 @@ yyreduce: case 125: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 611 "Grammar.y" { (yyvsp[(1) - (4)]).push_back((yyvsp[(2) - (4)]).front()); @@ -3287,7 +3295,7 @@ yyreduce: case 126: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 617 "Grammar.y" { parser->invalidCommand((yyvsp[(1) - (3)])); @@ -3297,7 +3305,7 @@ yyreduce: case 127: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 622 "Grammar.y" { parser->invalidCommand((yyvsp[(1) - (3)])); @@ -3307,7 +3315,7 @@ yyreduce: case 128: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 627 "Grammar.y" { yyerrok; @@ -3316,7 +3324,7 @@ yyreduce: case 129: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 631 "Grammar.y" { ;} @@ -3324,7 +3332,7 @@ yyreduce: case 130: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 640 "Grammar.y" { (yyval) = (yyvsp[(2) - (2)]); @@ -3334,7 +3342,7 @@ yyreduce: case 131: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 645 "Grammar.y" { (yyval) = (yyvsp[(2) - (2)]); @@ -3344,7 +3352,7 @@ yyreduce: case 132: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 650 "Grammar.y" { (yyval) = (yyvsp[(2) - (3)]); @@ -3355,7 +3363,7 @@ yyreduce: case 133: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 656 "Grammar.y" { (yyval) = (yyvsp[(2) - (3)]); @@ -3366,7 +3374,7 @@ yyreduce: case 134: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 662 "Grammar.y" { (yyval) = YYSTYPE(); @@ -3375,7 +3383,7 @@ yyreduce: case 135: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 671 "Grammar.y" { ;} @@ -3383,7 +3391,7 @@ yyreduce: case 136: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 674 "Grammar.y" { ;} @@ -3391,7 +3399,7 @@ yyreduce: case 137: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 677 "Grammar.y" { ;} @@ -3399,7 +3407,7 @@ yyreduce: case 138: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 680 "Grammar.y" { ;} @@ -3407,7 +3415,7 @@ yyreduce: case 139: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 683 "Grammar.y" { ;} @@ -3415,7 +3423,7 @@ yyreduce: case 140: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 686 "Grammar.y" { ;} @@ -3423,7 +3431,7 @@ yyreduce: case 141: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 689 "Grammar.y" { ;} @@ -3431,7 +3439,7 @@ yyreduce: case 142: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 692 "Grammar.y" { ;} @@ -3439,7 +3447,7 @@ yyreduce: case 143: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 695 "Grammar.y" { ;} @@ -3447,7 +3455,7 @@ yyreduce: case 144: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 698 "Grammar.y" { ;} @@ -3455,7 +3463,7 @@ yyreduce: case 145: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 701 "Grammar.y" { ;} @@ -3463,7 +3471,7 @@ yyreduce: case 146: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 704 "Grammar.y" { ;} @@ -3471,7 +3479,7 @@ yyreduce: case 147: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 707 "Grammar.y" { ;} @@ -3479,7 +3487,7 @@ yyreduce: case 148: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 710 "Grammar.y" { ;} @@ -3487,7 +3495,7 @@ yyreduce: case 149: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 713 "Grammar.y" { ;} @@ -3495,7 +3503,7 @@ yyreduce: case 150: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 716 "Grammar.y" { ;} @@ -3503,7 +3511,7 @@ yyreduce: case 151: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 719 "Grammar.y" { ;} @@ -3511,7 +3519,7 @@ yyreduce: case 152: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 722 "Grammar.y" { ;} @@ -3519,7 +3527,7 @@ yyreduce: case 153: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 725 "Grammar.y" { ;} @@ -3527,7 +3535,7 @@ yyreduce: case 154: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 728 "Grammar.y" { ;} @@ -3535,7 +3543,7 @@ yyreduce: case 155: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 731 "Grammar.y" { ;} @@ -3543,7 +3551,7 @@ yyreduce: case 156: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 734 "Grammar.y" { ;} @@ -3551,7 +3559,7 @@ yyreduce: case 157: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 737 "Grammar.y" { ;} @@ -3559,7 +3567,7 @@ yyreduce: case 158: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 740 "Grammar.y" { ;} @@ -3567,7 +3575,7 @@ yyreduce: case 159: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 743 "Grammar.y" { ;} @@ -3575,7 +3583,7 @@ yyreduce: case 160: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 746 "Grammar.y" { ;} @@ -3583,7 +3591,7 @@ yyreduce: case 161: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 749 "Grammar.y" { ;} @@ -3591,7 +3599,7 @@ yyreduce: case 162: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 752 "Grammar.y" { ;} @@ -3599,7 +3607,7 @@ yyreduce: case 163: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 755 "Grammar.y" { ;} @@ -3607,7 +3615,7 @@ yyreduce: case 164: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 758 "Grammar.y" { ;} @@ -3615,7 +3623,7 @@ yyreduce: case 165: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 761 "Grammar.y" { ;} @@ -3623,7 +3631,7 @@ yyreduce: case 166: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 764 "Grammar.y" { ;} @@ -3631,7 +3639,7 @@ yyreduce: case 167: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 767 "Grammar.y" { ;} @@ -3639,7 +3647,7 @@ yyreduce: case 168: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 770 "Grammar.y" { ;} @@ -3647,7 +3655,7 @@ yyreduce: case 169: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 773 "Grammar.y" { ;} @@ -3655,7 +3663,7 @@ yyreduce: case 170: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 776 "Grammar.y" { ;} @@ -3663,7 +3671,7 @@ yyreduce: case 171: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 779 "Grammar.y" { ;} @@ -3671,7 +3679,7 @@ yyreduce: case 172: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 782 "Grammar.y" { ;} @@ -3679,8 +3687,8 @@ yyreduce: -/* Line 1455 of yacc.c */ -#line 3684 "Grammar.tab.c" +/* Line 1464 of yacc.c */ +#line 3692 "Grammar.tab.c" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); diff --git a/cpp/src/IceGrid/Grammar.h b/cpp/src/IceGrid/Grammar.h index e39828c6ae7..5ed019cc349 100644 --- a/cpp/src/IceGrid/Grammar.h +++ b/cpp/src/IceGrid/Grammar.h @@ -1,10 +1,9 @@ - -/* A Bison parser, made by GNU Bison 2.4.1. */ +/* A Bison parser, made by GNU Bison 2.4.2. */ /* Skeleton interface for Bison's Yacc-like parsers in C - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 - Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2006, 2009-2010 Free Software + Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/cpp/src/IceGrid/Grammar.y b/cpp/src/IceGrid/Grammar.y index 98e69366156..6e96279c1d0 100644 --- a/cpp/src/IceGrid/Grammar.y +++ b/cpp/src/IceGrid/Grammar.y @@ -260,7 +260,7 @@ command } | ICE_GRID_NODE ICE_GRID_SHOW strings ';' { - parser->showFile("node", $3); + parser->show("node", $3); } | ICE_GRID_NODE ICE_GRID_SHOW ICE_GRID_HELP ';' { @@ -300,7 +300,7 @@ command } | ICE_GRID_REGISTRY ICE_GRID_SHOW strings ';' { - parser->showFile("registry", $3); + parser->show("registry", $3); } | ICE_GRID_REGISTRY ICE_GRID_SHOW ICE_GRID_HELP ';' { @@ -428,7 +428,7 @@ command } | ICE_GRID_SERVER ICE_GRID_SHOW strings ';' { - parser->showFile("server", $3); + parser->show("server", $3); } | ICE_GRID_SERVER ICE_GRID_SHOW ICE_GRID_HELP ';' { diff --git a/cpp/src/IceGrid/Parser.cpp b/cpp/src/IceGrid/Parser.cpp index 4af84b21243..951ef773f97 100644 --- a/cpp/src/IceGrid/Parser.cpp +++ b/cpp/src/IceGrid/Parser.cpp @@ -8,7 +8,7 @@ // ********************************************************************** #include <IceUtil/DisableWarnings.h> -#include <IceUtil/OutputUtil.h> +#include <IceUtil/IceUtil.h> #include <IceUtil/Options.h> #include <Ice/Ice.h> #include <IceXML/Parser.h> @@ -101,12 +101,12 @@ const char* _commandsHelp[][3] = { " node NAME or all the nodes if NAME is omitted.\n" }, { "node", "show", -"node show [OPTIONS] NAME [stderr | stdout]\n" -" Show node NAME stderr or stdout.\n" +"node show [OPTIONS] NAME [log | stderr | stdout]\n" +" Show node NAME Ice log, stderr or stdout.\n" " Options:\n" " -f | --follow: Wait for new data to be available\n" -" -t N | --tail N: Print the last N lines\n" -" -h N | --head N: Print the first N lines\n" +" -t N | --tail N: Print the last N log messages or lines\n" +" -h N | --head N: Print the first N lines (stderr and stdout only)\n" }, { "node", "shutdown", "node shutdown NAME Shutdown node NAME.\n" @@ -121,12 +121,12 @@ const char* _commandsHelp[][3] = { "registry ping NAME Ping registry NAME.\n" }, { "registry", "show", -"registry show [OPTIONS] NAME [stderr | stdout]\n" -" Show registry NAME stderr or stdout.\n" +"registry show [OPTIONS] NAME [log | stderr | stdout ]\n" +" Show registry NAME Ice log, stderr or stdout.\n" " Options:\n" -" -f | --follow: Wait for new data to be available\n" -" -t N | --tail N: Print the last N lines\n" -" -h N | --head N: Print the first N lines\n" +" -f | --follow: Wait for new log or data to be available\n" +" -t N | --tail N: Print the last N log messages or lines\n" +" -h N | --head N: Print the first N lines (stderr and stdout only)\n" }, { "registry", "shutdown", "registry shutdown NAME Shutdown registry NAME.\n" @@ -171,12 +171,12 @@ const char* _commandsHelp[][3] = { "server stderr ID MESSAGE Write MESSAGE on server ID's stderr.\n" }, { "server", "show", -"server show [OPTIONS] ID [stderr | stdout | LOGFILE ]\n" -" Show server ID stderr, stdout or log file LOGFILE.\n" +"server show [OPTIONS] ID [log | stderr | stdout | LOGFILE ]\n" +" Show server ID Ice log, stderr, stdout or log file LOGFILE.\n" " Options:\n" " -f | --follow: Wait for new data to be available\n" -" -t N | --tail N: Print the last N lines\n" -" -h N | --head N: Print the first N lines\n" +" -t N | --tail N: Print the last N log messages or lines\n" +" -h N | --head N: Print the first N lines (not available for Ice log)\n" }, { "server", "enable", "server enable ID Enable server ID.\n" @@ -243,6 +243,141 @@ const char* _commandsHelp[][3] = { { 0, 0, 0 } }; + +void writeMessage(const string& message, bool indent) +{ + string s = message; + + if(indent) + { + string::size_type idx = 0; + while((idx = s.find("\n", idx)) != string::npos) + { + s.insert(idx + 1, " "); + ++idx; + } + } + + // TODO: Console handling on Windows + + cout << s << endl; +} + +void printLogMessage(const string& p, const Ice::LogMessage& logMessage) +{ + string prefix = p; + + if(!prefix.empty()) + { + prefix += ": "; + } + + string timestamp = IceUtil::Time::microSeconds(logMessage.timestamp).toDateTime(); + + switch(logMessage.type) + { + case Ice::PrintMessage: + { + writeMessage(timestamp + " " + logMessage.message, false); + break; + } + case Ice::TraceMessage: + { + string s = "-- " + timestamp + " " + prefix; + if(!logMessage.traceCategory.empty()) + { + s += logMessage.traceCategory + ": "; + } + s += logMessage.message; + writeMessage(s, true); + break; + } + case Ice::WarningMessage: + { + writeMessage("!- " + timestamp + " " + prefix + "warning: " + logMessage.message, true); + break; + } + case Ice::ErrorMessage: + { + writeMessage("!! " + timestamp + " " + prefix + "error: " + logMessage.message, true); + break; + } + default: + { + assert(0); + } + } +} + + + +class RemoteLoggerI : public Ice::RemoteLogger +{ +public: + + RemoteLoggerI(); + + virtual void init(const string&, const Ice::LogMessageSeq&, const Ice::Current&); + virtual void log(const Ice::LogMessage&, const Ice::Current&); + + void destroy(); + +private: + + IceUtil::Monitor<IceUtil::Mutex> _monitor; + bool _initDone; + bool _destroyed; + string _prefix; +}; + +typedef IceUtil::Handle<RemoteLoggerI> RemoteLoggerIPtr; + +RemoteLoggerI::RemoteLoggerI() : + _initDone(false), + _destroyed(false) +{ +} + +void +RemoteLoggerI::init(const string& prefix, const Ice::LogMessageSeq& logMessages, const Ice::Current&) +{ + IceUtil::Monitor<IceUtil::Mutex>::Lock lock(_monitor); + if(!_destroyed) + { + _prefix = prefix; + + for(Ice::LogMessageSeq::const_iterator p = logMessages.begin(); p != logMessages.end(); ++p) + { + printLogMessage(_prefix, *p); + } + + _initDone = true; + _monitor.notifyAll(); + } +} + +void +RemoteLoggerI::log(const Ice::LogMessage& logMessage, const Ice::Current&) +{ + IceUtil::Monitor<IceUtil::Mutex>::Lock lock(_monitor); + while(!_initDone && !_destroyed) + { + _monitor.wait(); + } + if(!_destroyed) + { + printLogMessage(_prefix, logMessage); + } +} + +void +RemoteLoggerI::destroy() +{ + IceUtil::Monitor<IceUtil::Mutex>::Lock lock(_monitor); + _destroyed = true; + _monitor.notifyAll(); +} + } namespace IceGrid @@ -1975,7 +2110,7 @@ Parser::listObject(const list<string>& args) } void -Parser::showFile(const string& reader, const list<string>& origArgs) +Parser::show(const string& reader, const list<string>& origArgs) { list<string> copyArgs = origArgs; copyArgs.push_front("icegridadmin"); @@ -2022,8 +2157,13 @@ Parser::showFile(const string& reader, const list<string>& origArgs) invalidCommand("can't specify both -h | --head and -t | --tail options"); return; } + if(head && reader == "log") + { + invalidCommand("can't specify -h | --head option with log"); + return; + } + int lineCount = 20; - int maxBytes = _communicator->getProperties()->getPropertyAsIntWithDefault("Ice.MessageSizeMax", 1024) * 1024; if(head || tail) { if(head) @@ -2042,8 +2182,41 @@ Parser::showFile(const string& reader, const list<string>& origArgs) return; } } + + bool follow = opts.isSet("follow"); + + if(head && follow) + { + invalidCommand("can't use -f | --follow option with -h | --head option"); + return; + } - FileIteratorPrx it; + if(filename == "log") + { + showLog(id, reader, tail, follow, lineCount); + } + else + { + showFile(id, reader, filename, head, tail, follow, lineCount); + } + } + catch(const Ice::Exception& ex) + { + exception(ex); + } +} + +void +Parser::showFile(const string& id, const string& reader, const string& filename, + bool head, bool tail, bool follow, int lineCount) +{ + + int maxBytes = _communicator->getProperties()->getPropertyAsIntWithDefault("Ice.MessageSizeMax", 1024) * 1024; + + FileIteratorPrx it; + + try + { if(reader == "node") { if(filename == "stderr") @@ -2091,17 +2264,13 @@ Parser::showFile(const string& reader, const list<string>& origArgs) it = _session->openServerLog(id, filename, tail ? lineCount : -1); } } - - bool follow = opts.isSet("follow"); + resetInterrupt(); + Ice::StringSeq lines; if(head) { - if(follow) - { - invalidCommand("can't use -f | --follow option with -h | --head option"); - return; - } - + assert(!follow); + int i = 0; bool eof = false; while(!interrupted() && !eof && i < lineCount) @@ -2125,7 +2294,7 @@ Parser::showFile(const string& reader, const list<string>& origArgs) } } } - + if(follow) { while(!interrupted()) @@ -2143,7 +2312,7 @@ Parser::showFile(const string& reader, const list<string>& origArgs) cout << flush; } } - + if(eof) { Lock sync(*this); @@ -2155,17 +2324,136 @@ Parser::showFile(const string& reader, const list<string>& origArgs) } } } - + if(lines.empty() || !lines.back().empty()) { cout << endl; } - + it->destroy(); } - catch(const Ice::Exception& ex) + catch(...) { - exception(ex); + if(it != 0) + { + try + { + it->destroy(); + } + catch(...) + { + } + } + throw; + } +} + +void +Parser::showLog(const string& id, const string& reader, bool tail, bool follow, int lineCount) +{ + cout << endl; + + if(reader == "server") + { + Ice::ObjectPrx serverAdmin = _admin->getServerAdmin(id); + + Ice::LoggerAdminPrx loggerAdmin; + try + { + loggerAdmin = Ice::LoggerAdminPrx::checkedCast(serverAdmin, "Logger"); + } + catch(const Ice::Exception&) + { + loggerAdmin = 0; + } + + if(loggerAdmin == 0) + { + error("cannot retrieve Logger facet for server '" + id + "'"); + return; + } + + if(follow) + { + Ice::ObjectPrx adminCallbackTemplate = _session->getAdminCallbackTemplate(); + + if(adminCallbackTemplate == 0) + { + error("cannot retriever Callback template from IceGrid registry"); + return; + } + + const Ice::EndpointSeq endpoints = adminCallbackTemplate->ice_getEndpoints(); + string publishedEndpoints; + + for(Ice::EndpointSeq::const_iterator p = endpoints.begin(); p != endpoints.end(); ++p) + { + if(publishedEndpoints.empty()) + { + publishedEndpoints = (*p)->toString(); + } + else + { + publishedEndpoints += ":" + (*p)->toString(); + } + } + + _communicator->getProperties()->setProperty("RemoteLoggerAdapter.PublishedEndpoints", publishedEndpoints); + + Ice::ObjectAdapterPtr adapter = + _communicator->createObjectAdapter("RemoteLoggerAdapter"); + + _session->ice_getConnection()->setAdapter(adapter); + + Ice::Identity id; + id.name = "RemoteLogger-" + IceUtil::generateUUID(); + id.category = adminCallbackTemplate->ice_getIdentity().category; + + RemoteLoggerIPtr servant = new RemoteLoggerI; + Ice::RemoteLoggerPrx prx = + Ice::RemoteLoggerPrx::uncheckedCast(adapter->add(servant, id)); + adapter->activate(); + + loggerAdmin->attachRemoteLogger(prx, Ice::LogMessageTypeSeq(), Ice::StringSeq(), + tail ? lineCount : -1); + + resetInterrupt(); + { + Lock lock(*this); + while(!_interrupted) + { + wait(); + } + } + + servant->destroy(); + adapter->destroy(); + + try + { + loggerAdmin->detachRemoteLogger(prx); + } + catch(const Ice::ObjectNotExistException&) + { + // ignored + } + catch(const Ice::RemoteLoggerNotAttachedException&) + { + // ignored + } + } + else + { + string prefix; + const Ice::LogMessageSeq logMessages = + loggerAdmin->getLog(Ice::LogMessageTypeSeq(), Ice::StringSeq(), + tail ? lineCount : -1, prefix); + + for(Ice::LogMessageSeq::const_iterator p = logMessages.begin(); p != logMessages.end(); ++p) + { + printLogMessage(prefix, *p); + } + } } } diff --git a/cpp/src/IceGrid/Parser.h b/cpp/src/IceGrid/Parser.h index af22bd5aade..bfd08d10438 100644 --- a/cpp/src/IceGrid/Parser.h +++ b/cpp/src/IceGrid/Parser.h @@ -120,8 +120,8 @@ public: void describeObject(const std::list<std::string>&); void listObject(const std::list<std::string>&); - void showFile(const std::string&, const std::list<std::string>&); - + void show(const std::string&, const std::list<std::string>&); + void showBanner(); void showCopying(); void showWarranty(); @@ -151,6 +151,10 @@ private: Parser(const Ice::CommunicatorPtr&, const AdminSessionPrx&, const AdminPrx&, bool); void exception(const Ice::Exception&); + void showFile(const std::string&, const std::string&, const std::string&, bool, bool, bool, int); + void showLog(const std::string&, const std::string&, bool, bool, int); + + std::string _commands; Ice::CommunicatorPtr _communicator; AdminSessionPrx _session; diff --git a/cpp/src/IceGrid/Scanner.cpp b/cpp/src/IceGrid/Scanner.cpp index 442e3a6697c..45fded5ae27 100644 --- a/cpp/src/IceGrid/Scanner.cpp +++ b/cpp/src/IceGrid/Scanner.cpp @@ -1,4 +1,4 @@ -#include <IceUtil/ScannerConfig.h> +#include "IceUtil/ScannerConfig.h" #line 3 "lex.yy.c" @@ -612,7 +612,7 @@ static int input (void ); /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ -#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) +#define ECHO fwrite( yytext, yyleng, 1, yyout ) #endif /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, @@ -623,7 +623,7 @@ static int input (void ); if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ { \ int c = '*'; \ - unsigned n; \ + int n; \ for ( n = 0; n < max_size && \ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ buf[n] = (char) c; \ |