[asterisk-scf-commits] asterisk-scf/integration/logger.git branch "master" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Fri Sep 24 11:52:26 CDT 2010
branch "master" has been updated
via 2ced70031ce47fa1f4618107207b186cf0580b3a (commit)
via 9a68d1515dd3206e9e866bc55344ee669017cc0d (commit)
via af4b52241753c52199e19d4b56187b7d54cb13ba (commit)
from 004b92995eeb30758c12fac714480710f618880d (commit)
Summary of changes:
client/config/logging-client.conf | 7 +-
client/src/CMakeLists.txt | 4 +
client/src/IceLogger.cpp | 164 ++++++++++++++++++-----
client/src/IceLogger.h | 82 +++++++++++
client/{test/client-test.cpp => src/LogOut.cpp} | 10 +-
client/src/LogOut.h | 36 +++++
client/src/Logger.cpp | 5 -
client/src/logger.h | 29 +----
client/test/scf-log.cpp | 42 +++++--
ice/LoggerIf.ice | 14 ++
server/config/logging-server.conf | 2 +-
server/src/LoggingServer.cpp | 53 ++++++--
server/src/LoggingServer.h | 10 +-
server/src/main.cpp | 2 +-
server/test/LoggingServer-test.cpp | 21 +++
15 files changed, 385 insertions(+), 96 deletions(-)
create mode 100644 client/src/IceLogger.h
copy client/{test/client-test.cpp => src/LogOut.cpp} (54%)
create mode 100644 client/src/LogOut.h
- Log -----------------------------------------------------------------
commit 2ced70031ce47fa1f4618107207b186cf0580b3a
Author: David M. Lee <dlee at digium.com>
Date: Fri Sep 24 11:26:47 2010 -0500
Fixed client side logger issues.
diff --git a/client/src/IceLogger.cpp b/client/src/IceLogger.cpp
index c026eb9..e65e486 100644
--- a/client/src/IceLogger.cpp
+++ b/client/src/IceLogger.cpp
@@ -57,7 +57,6 @@ ConfiguredIceLogger::ConfiguredIceLogger(ServiceLocatorPrx locator) :
void ConfiguredIceLogger::updateLoggerFromServiceLocator()
{
- std::clog << __func__ << '\n';
if (locator)
{
try
@@ -164,6 +163,7 @@ ConfiguredIceLoggerPtr AsteriskSCF::System::Logging::createIceLogger(
Ice::ObjectPrx proxy = adapter->addWithUUID(logger)->ice_oneway();
IceStorm::TopicPrx topic = topicManager->retrieve(Discovery::TOPIC);
topic->subscribeAndGetPublisher(IceStorm::QoS(), proxy);
+ adapter->activate();
}
else
{
diff --git a/client/test/scf-log.cpp b/client/test/scf-log.cpp
index 75a98c6..672a87b 100644
--- a/client/test/scf-log.cpp
+++ b/client/test/scf-log.cpp
@@ -82,13 +82,16 @@ int ScfLogClientApplication::run(int argc, char *argv[])
ConfiguredIceLoggerPtr logger = createIceLogger(
communicator()->createObjectAdapter(AdapterName));
- LoggerFactory factory(logger->getLogger());
-
- while (true)
+ if (logger)
+ {
+ LoggerFactory factory(logger->getLogger());
+ factory.getLogger(name).logs(level, message);
+ }
+ else
{
- factory.getLogger(name).logs(level, message);
- sleep(1);
+ std::clog << "Could not log.\n";
}
+
return EXIT_SUCCESS;
}
commit 9a68d1515dd3206e9e866bc55344ee669017cc0d
Author: David M. Lee <dlee at digium.com>
Date: Fri Sep 24 11:18:47 2010 -0500
Wired up for clients to get server changes, but it's not happening.
diff --git a/client/config/logging-client.conf b/client/config/logging-client.conf
index 57909d5..0ae8e15 100644
--- a/client/config/logging-client.conf
+++ b/client/config/logging-client.conf
@@ -1,7 +1,12 @@
# Configuration file for the logging client
+AsteriskSCF.LoggingClient.Endpoints=default
+
# Optionally directly specify LoggerServer proxy string
#LoggerServer.Proxy=5BC84ACA-3F4C-4B78-BC75-5E6B1CC98680:tcp -h 10.24.21.100 -p 51030
# Where to find the Service Locator.
-LocatorService.Proxy=LocatorService:tcp -p 4411
\ No newline at end of file
+LocatorService.Proxy=LocatorService:tcp -p 4411
+
+# A proxy to the IceStorm topic manager
+TopicManager.Proxy=HydraIceStorm/TopicManager:default -p 10000
diff --git a/client/src/CMakeLists.txt b/client/src/CMakeLists.txt
index a918910..8115598 100644
--- a/client/src/CMakeLists.txt
+++ b/client/src/CMakeLists.txt
@@ -12,13 +12,17 @@ include_directories(../../common)
hydra_component_add_file(logging-client Logger.cpp)
hydra_component_add_file(logging-client LoggerFactory.cpp)
+hydra_component_add_file(logging-client LogOut.cpp)
hydra_component_add_file(logging-client IceLogger.cpp)
hydra_component_add_file(logging-client OstreamLogger.cpp)
hydra_component_add_file(logging-client logger.h)
+hydra_component_add_file(logging-client LogOut.h)
hydra_component_add_slice(logging-client LoggerIf)
hydra_component_add_slice(logging-client ServiceLocatorIf)
+hydra_component_add_slice(logging-client ServiceLocatorEventsIf)
hydra_add_boost_libraries(thread)
+hydra_add_ice_libraries(IceStorm)
hydra_component_build_library(logging-client)
diff --git a/client/src/IceLogger.cpp b/client/src/IceLogger.cpp
index 8cd1002..c026eb9 100644
--- a/client/src/IceLogger.cpp
+++ b/client/src/IceLogger.cpp
@@ -6,48 +6,137 @@
* All rights reserved.
*/
-#include <Ice/Ice.h>
+#include <IceStorm/IceStorm.h>
#include "Core/Discovery/ServiceLocatorIf.h"
-#include "logger.h"
+#include "IceLogger.h"
+#include "Level.h"
using namespace AsteriskSCF::Core::Discovery::V1;
using namespace AsteriskSCF::System::Logging;
-namespace
+void IceLogger::logs(std::string const &name, Level logLevel,
+ std::string const &message)
{
-
-class IceLogger : public LogOut
-{
-public:
- IceLogger(LoggingServerPrx const &server) :
- server(server->ice_oneway()) // use oneway to not block on calls
+ bool logged = false;
+ try
+ {
+ if (server)
+ {
+ server->logs(name, logLevel, message);
+ logged = true;
+ }
+ }
+ catch (std::exception const &e)
+ {
+ std::clog << "Error contacting server: " << e.what() << '\n';
+ }
+ catch (...)
{
+ std::clog << "Error contacting server";
}
- void logs(std::string const &name, Level logLevel,
- std::string const &message)
+ if (!logged)
{
- server->logs(name, logLevel, message);
+ std::clog << "(no server) " << name << ":" << logLevel << ":" << message
+ << '\n';
}
+}
+
+ConfiguredIceLogger::ConfiguredIceLogger(LoggingServerPrx server)
+{
+ logger.setServer(server);
+}
-private:
- LoggingServerPrx server;
-};
+ConfiguredIceLogger::ConfiguredIceLogger(ServiceLocatorPrx locator) :
+ locator(locator)
+{
+ //updateLoggerFromServiceLocator();
+}
+void ConfiguredIceLogger::updateLoggerFromServiceLocator()
+{
+ std::clog << __func__ << '\n';
+ if (locator)
+ {
+ try
+ {
+ ServiceLocatorParamsPtr loggingServerParams =
+ new ServiceLocatorParams();
+ Ice::ObjectPrx serverObject = locator->locate(loggingServerParams);
+ if (serverObject)
+ {
+ LoggingServerPrx server = LoggingServerPrx::checkedCast(
+ serverObject);
+ logger.setServer(server);
+ }
+ }
+ catch (Core::Discovery::V1::ServiceNotFound const &r)
+ {
+ // couldn't find the service;
+ logger.setServer(LoggingServerPrx());
+ }
+ }
}
-LoggingServerPrx AsteriskSCF::System::Logging::locateLoggerProxy(
- Ice::CommunicatorPtr com)
+void ConfiguredIceLogger::comparisonRegistered(std::string const &guid,
+ Ice::Current const &)
{
+ // no-op
+}
+void ConfiguredIceLogger::comparisonUnregistered(std::string const &guid,
+ Ice::Current const &)
+{
+ // no-op
+}
+void ConfiguredIceLogger::serviceRegistered(std::string const &guid,
+ Ice::Current const &)
+{
+ if (guid == LoggingServerGuid)
+ {
+ updateLoggerFromServiceLocator();
+ }
+}
+void ConfiguredIceLogger::serviceUnregistered(std::string const &guid,
+ Ice::Current const &)
+{
+ if (guid == LoggingServerGuid)
+ {
+ updateLoggerFromServiceLocator();
+ }
+}
+void ConfiguredIceLogger::serviceSuspended(std::string const &guid,
+ Ice::Current const &)
+{
+ if (guid == LoggingServerGuid)
+ {
+ updateLoggerFromServiceLocator();
+ }
+}
+void ConfiguredIceLogger::serviceUnsuspended(std::string const &guid,
+ Ice::Current const &)
+{
+ if (guid == LoggingServerGuid)
+ {
+ updateLoggerFromServiceLocator();
+ }
+}
+
+ConfiguredIceLoggerPtr AsteriskSCF::System::Logging::createIceLogger(
+ Ice::ObjectAdapterPtr adapter)
+{
+ Ice::CommunicatorPtr communicator = adapter->getCommunicator();
+
// If directly specified, use that.
try
{
- Ice::ObjectPrx r = com->propertyToProxy("LoggerServer.Proxy");
- if (r)
+ Ice::ObjectPrx server = communicator->propertyToProxy(
+ "LoggerServer.Proxy");
+ if (server)
{
- return LoggingServerPrx::checkedCast(r);
+ return ConfiguredIceLoggerPtr(new ConfiguredIceLogger(
+ LoggingServerPrx::checkedCast(server)));
}
}
catch (std::exception const &e)
@@ -59,15 +148,30 @@ LoggingServerPrx AsteriskSCF::System::Logging::locateLoggerProxy(
// then try the service locator.
try
{
+ IceStorm::TopicManagerPrx topicManager =
+ IceStorm::TopicManagerPrx::checkedCast(communicator->propertyToProxy(
+ "TopicManager.Proxy"));
+
ServiceLocatorPrx locator = ServiceLocatorPrx::checkedCast(
- com->propertyToProxy("LocatorService.Proxy"));
+ communicator->propertyToProxy("LocatorService.Proxy"));
if (locator)
{
- ServiceLocatorParamsPtr loggingServerParams =
- new ServiceLocatorParams();
- return LoggingServerPrx::checkedCast(locator->locate(
- loggingServerParams));
+ ConfiguredIceLoggerPtr logger = new ConfiguredIceLogger(locator);
+ // register with IceStorm for callbacks
+ if (topicManager)
+ {
+ Ice::ObjectPrx proxy = adapter->addWithUUID(logger)->ice_oneway();
+ IceStorm::TopicPrx topic = topicManager->retrieve(Discovery::TOPIC);
+ topic->subscribeAndGetPublisher(IceStorm::QoS(), proxy);
+ }
+ else
+ {
+ std::clog << "IceStorm unavailable. Will not receive updates.\n";
+ }
+ logger->updateLoggerFromServiceLocator();
+
+ return logger;
}
}
catch (std::exception const &e)
@@ -76,12 +180,8 @@ LoggingServerPrx AsteriskSCF::System::Logging::locateLoggerProxy(
std::clog << e.what() << '\n';
}
- // couldn't find the proxy
- return LoggingServerPrx();
-}
+ std::clog << "Failed to construct Logger proxy.\n";
-std::auto_ptr<LogOut> AsteriskSCF::System::Logging::buildIceLogger(
- LoggingServerPrx const &server)
-{
- return std::auto_ptr<LogOut>(new IceLogger(server));
+ // couldn't find the proxy
+ return ConfiguredIceLoggerPtr();
}
diff --git a/client/src/IceLogger.h b/client/src/IceLogger.h
new file mode 100644
index 0000000..6785761
--- /dev/null
+++ b/client/src/IceLogger.h
@@ -0,0 +1,82 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
+
+#pragma once
+
+#include <Ice/Ice.h>
+
+#include "Core/Discovery/ServiceLocatorIf.h"
+#include "Core/Discovery/ServiceLocatorEventsIf.h"
+#include "LogOut.h"
+
+namespace AsteriskSCF
+{
+namespace System
+{
+namespace Logging
+{
+
+/**
+ * A LogOut which logs to a LoggingServer.
+ */
+class IceLogger : public LogOut
+{
+public:
+ void logs(std::string const &name, Level logLevel,
+ std::string const &message);
+
+ LoggingServerPrx getServer() const { return server; }
+ void setServer(LoggingServerPrx server) { this->server = server; }
+
+private:
+ LoggingServerPrx server;
+};
+
+/**
+ * An IceLogger which pulls its configuration from the communicator. If using
+ * the ServiceLocator, this will keep the logger's proxy reference up to date.
+ */
+class ConfiguredIceLogger : public Discovery::Events
+{
+public:
+ /**
+ * Configure an IceLogger directly with the LoggingServer.
+ *
+ * @param server Server proxy to log to.
+ */
+ ConfiguredIceLogger(LoggingServerPrx server);
+ /**
+ * Configure an IceLogger which gets LoggingServer from the ServiceLocator.
+ *
+ * @param locator Locator to use to get the LoggingServer proxy.
+ */
+ ConfiguredIceLogger(Core::Discovery::V1::ServiceLocatorPrx locator);
+
+ LogOut &getLogger() { return logger; }
+
+ void updateLoggerFromServiceLocator();
+
+ void comparisonRegistered(std::string const &guid, Ice::Current const &);
+ void comparisonUnregistered(std::string const &guid, Ice::Current const &);
+ void serviceRegistered(std::string const &guid, Ice::Current const &);
+ void serviceUnregistered(std::string const &guid, Ice::Current const &);
+ void serviceSuspended(std::string const &guid, Ice::Current const &);
+ void serviceUnsuspended(std::string const &guid, Ice::Current const &);
+
+private:
+ IceLogger logger;
+ Core::Discovery::V1::ServiceLocatorPrx locator;
+};
+
+typedef IceUtil::Handle<ConfiguredIceLogger> ConfiguredIceLoggerPtr;
+
+ConfiguredIceLoggerPtr createIceLogger(Ice::ObjectAdapterPtr adapter);
+
+} // Logging
+} // System
+} // AsteriskSCF
diff --git a/client/src/LogOut.cpp b/client/src/LogOut.cpp
new file mode 100644
index 0000000..40c4484
--- /dev/null
+++ b/client/src/LogOut.cpp
@@ -0,0 +1,16 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
+
+#include "LogOut.h"
+
+using namespace AsteriskSCF::System::Logging;
+
+LogOut::~LogOut()
+{
+ // no-op
+}
diff --git a/client/src/LogOut.h b/client/src/LogOut.h
new file mode 100644
index 0000000..cb1434b
--- /dev/null
+++ b/client/src/LogOut.h
@@ -0,0 +1,36 @@
+/*
+ * Asterisk Scalable Communications Framework
+ *
+ * Copyright (C) 2010 -- Digium, Inc.
+ *
+ * All rights reserved.
+ */
+
+#pragma once
+
+#include <string>
+
+#include "LoggerIf.h"
+
+namespace AsteriskSCF
+{
+namespace System
+{
+namespace Logging
+{
+
+/**
+ * Interface abstracting how the logs actually get written.
+ */
+class LogOut
+{
+public:
+ virtual ~LogOut();
+ virtual void logs(std::string const &name, Level logLevel,
+ std::string const &message) = 0;
+};
+
+
+} // Logging
+} // System
+} // AsteriskSCF
diff --git a/client/src/Logger.cpp b/client/src/Logger.cpp
index c9c79c2..a058d7a 100644
--- a/client/src/Logger.cpp
+++ b/client/src/Logger.cpp
@@ -13,11 +13,6 @@
using namespace AsteriskSCF::System::Logging;
-LogOut::~LogOut()
-{
- // no-op
-}
-
LogBuf::LogBuf(LogOut &out, std::string const &name, Level logLevel) :
out(out), name(name), logLevel(logLevel)
{
diff --git a/client/src/logger.h b/client/src/logger.h
index 519d798..1fdac36 100644
--- a/client/src/logger.h
+++ b/client/src/logger.h
@@ -14,6 +14,7 @@
#include "LoggerIf.h"
#include "Level.h"
+#include "LogOut.h"
namespace AsteriskSCF
{
@@ -23,17 +24,6 @@ namespace Logging
{
/**
- * Interface abstracting how the logs actually get written.
- */
-class LogOut
-{
-public:
- virtual ~LogOut();
- virtual void logs(std::string const &name, Level logLevel,
- std::string const &message) = 0;
-};
-
-/**
* A streambuf for writing to a LogOut. Messages are written at newlines (\n)
* or when destroyed. The way temporary object lifecycles work in C++, this is
* very convenient.
@@ -263,23 +253,6 @@ private:
Logger root;
};
-/**
- * Attempts several different methods of locating the LoggingServer. It uses
- * Communicator properties to find the LoggingServer.
- *
- * <ol>
- * <li><em>LoggerServer.Proxy</em> - Directly specify the proxy string for
- * the LoggerServer</li>
- * <li><em>LocatorService.Proxy</em> - Specify the proxy for the
- * LocatorService.</li>
- * </ol>
- *
- * @return Proxy to the LoggingServer, which will be null if it could not be
- * located.
- */
-LoggingServerPrx locateLoggerProxy(Ice::CommunicatorPtr communicator);
-
-std::auto_ptr<LogOut> buildIceLogger(LoggingServerPrx const &server);
std::auto_ptr<LogOut> buildOstreamLogger(std::ostream &out);
/**
diff --git a/client/test/scf-log.cpp b/client/test/scf-log.cpp
index 86d5e7d..75a98c6 100644
--- a/client/test/scf-log.cpp
+++ b/client/test/scf-log.cpp
@@ -9,6 +9,7 @@
#include <Ice/Ice.h>
#include <unistd.h>
+#include "IceLogger.h"
#include "logger.h"
using namespace AsteriskSCF::System::Logging;
@@ -16,6 +17,7 @@ using namespace AsteriskSCF::System::Logging;
const std::string DefaultName = "AsteriskSCF.System.Logger";
const Level DefaultLevel = Info;
const std::string DefaultMessage = "-- MARK --";
+const std::string AdapterName = "AsteriskSCF.LoggingClient";
namespace
{
@@ -26,7 +28,9 @@ public:
int run(int argc, char *argv[]);
void usage(std::ostream &out);
private:
- LoggingServerPrx getLoggerProxy();
+ void setupDefaultProperties();
+ void setDefaultProperty(Ice::Properties &properties, std::string const &key,
+ std::string const &defaultValue);
};
} // namespace
@@ -73,17 +77,18 @@ int ScfLogClientApplication::run(int argc, char *argv[])
++argv;
}
- LoggingServerPrx logger = locateLoggerProxy(communicator());
- if (!logger)
- {
- std::clog << "Could not get proxy to LoggingServer.\n";
- return EXIT_FAILURE;
- }
+ setupDefaultProperties();
- std::auto_ptr<LogOut> logOut = buildIceLogger(logger);
- LoggerFactory factory(*logOut);
+ ConfiguredIceLoggerPtr logger = createIceLogger(
+ communicator()->createObjectAdapter(AdapterName));
+ LoggerFactory factory(logger->getLogger());
+
+ while (true)
+ {
factory.getLogger(name).logs(level, message);
+ sleep(1);
+ }
return EXIT_SUCCESS;
}
@@ -92,6 +97,22 @@ void ScfLogClientApplication::usage(std::ostream &out)
out << "Usage: scf-log [-p pri] [-t tag] message...\n";
}
+void ScfLogClientApplication::setupDefaultProperties()
+{
+ Ice::PropertiesPtr props = communicator()->getProperties();
+
+ setDefaultProperty(*props, AdapterName + ".Endpoints", "default");
+}
+
+void ScfLogClientApplication::setDefaultProperty(Ice::Properties &props,
+ std::string const &key, std::string const &defaultValue)
+{
+ if (props.getProperty(key).empty())
+ {
+ props.setProperty(key, defaultValue);
+ }
+}
+
int main(int argc, char *argv[])
{
ScfLogClientApplication app;
diff --git a/ice/LoggerIf.ice b/ice/LoggerIf.ice
index 2a1bd24..939adf1 100644
--- a/ice/LoggerIf.ice
+++ b/ice/LoggerIf.ice
@@ -15,7 +15,15 @@ module System
module Logging
{
+/**
+ * Category for locating the LoggingServer in the ServiceLocator.
+ */
const string LoggingServerCategory = "LoggingServer";
+/**
+ * Guid for listenting to LoggingServer registration events from the
+ * ServiceLocator.
+ */
+const string LoggingServerGuid = "LoggingServer";
/**
* Warning levels, inspired by syslog.
diff --git a/server/config/logging-server.conf b/server/config/logging-server.conf
index 6428656..faf6ba4 100644
--- a/server/config/logging-server.conf
+++ b/server/config/logging-server.conf
@@ -1,7 +1,7 @@
# Configuration file for the logging server
# Ice config
-AsteriskSCF.LoggingService.Endpoints=default #-p 4433
+AsteriskSCF.LoggingService.Endpoints=default
# A proxy to the service locator management service
ServiceLocatorManagement.Proxy=LocatorServiceManagement:tcp -p 4422
diff --git a/server/src/main.cpp b/server/src/main.cpp
index b634d1a..0b1f494 100644
--- a/server/src/main.cpp
+++ b/server/src/main.cpp
@@ -50,7 +50,7 @@ void LoggingServerDaemon::registerWithServiceLocator(
ServiceLocatorManagementPrx::checkedCast(
communicator()->stringToProxy(locatorManagementProxyString));
serviceManagement = management->addService(serverProxy,
- "LoggingService");
+ LoggingServerGuid);
ServiceLocatorParamsPtr params = new ServiceLocatorParams(LoggingServerCategory);
serviceManagement->addLocatorParams(params, "");
}
commit af4b52241753c52199e19d4b56187b7d54cb13ba
Author: David M. Lee <dlee at digium.com>
Date: Fri Sep 24 08:45:33 2010 -0500
Added LoggingServerI::getConfiguration.
diff --git a/ice/LoggerIf.ice b/ice/LoggerIf.ice
index 6c0c2cd..2a1bd24 100644
--- a/ice/LoggerIf.ice
+++ b/ice/LoggerIf.ice
@@ -80,6 +80,12 @@ interface LoggingServer
*/
["cpp:const"]
idempotent void logs(string name, Level logLevel, string message);
+
+ /**
+ * Returns the current configuration for this server.
+ */
+ ["cpp:const"]
+ idempotent Configuration getConfiguration();
};
/**
diff --git a/server/src/LoggingServer.cpp b/server/src/LoggingServer.cpp
index 10c3c14..f8392c4 100644
--- a/server/src/LoggingServer.cpp
+++ b/server/src/LoggingServer.cpp
@@ -29,9 +29,17 @@ std::string getCurrentTime()
} // namespace
-const std::string LoggingServerI::LoggingPropertyPrefix = "AsteriskSCF.Logging.";
-const std::string RootLoggerProperty = LoggingServerI::LoggingPropertyPrefix + "logger";
-const std::string LoggerPrefix = LoggingServerI::LoggingPropertyPrefix + "logger.";
+const std::string LoggingServerI::LoggingPropertyPrefix =
+ "AsteriskSCF.Logging.";
+const std::string RootLoggerProperty = LoggingServerI::LoggingPropertyPrefix
+ + "logger";
+const std::string LoggerPrefix = LoggingServerI::LoggingPropertyPrefix
+ + "logger.";
+
+LoggingServerI::LoggingServerI()
+{
+ sources[""] = SourceNode();
+}
bool LoggingServerI::isEnabledFor(std::string const &name, Level level) const
{
@@ -46,8 +54,8 @@ Level LoggingServerI::getEffectiveLevel(std::string const &name) const
// this is they the map is reverse sorted. find the first entry where
// the source key is a substring of the source we're looking for, where
// the substring
- for (Sources::const_iterator i = sources.lower_bound(name);
- i != sources.end(); ++i)
+ for (Sources::const_iterator i = sources.lower_bound(name); i
+ != sources.end(); ++i)
{
if (isSubpathOf(name, i->first))
{
@@ -67,7 +75,7 @@ void LoggingServerI::setLevel(std::string const &name, Level level)
}
void LoggingServerI::logs(std::string const &name, Level level,
- const std::string &message, const Ice::Current&) const
+ const std::string &message, const Ice::Current&) const
{
if (isEnabledFor(name, level))
{
@@ -75,8 +83,28 @@ void LoggingServerI::logs(std::string const &name, Level level,
}
}
+Configuration LoggingServerI::getConfiguration() const
+{
+ Configuration r;
+
+ // thread safety
+ IceUtil::Mutex::Lock sourcesLock(sourcesMutex);
+
+ // reverse sorted is a bit confusing for the outside world, so
+ // double-reverse for a normal sort.
+ for (Sources::const_reverse_iterator i = sources.rbegin(); i
+ != sources.rend(); ++i)
+ {
+ SourceConfiguration v = {};
+ v.name = i->first;
+ v.logLevel = i->second.getLevel();
+ r.sourceSettings.push_back(v);
+ }
+ return r;
+}
+
void LoggingServerI::reallyLog(std::string const &name, Level level,
- const std::string &message) const
+ const std::string &message) const
{
// date level name(1) message
std::string::size_type lastDot = name.rfind('.');
@@ -89,14 +117,13 @@ void LoggingServerI::reallyLog(std::string const &name, Level level,
IceUtil::Mutex::Lock sourcesLock(outputMutex);
std::ostream::fmtflags flags = std::cout.flags();
std::cout << getCurrentTime() << ' ' << std::setw(9) << level << ' '
- << std::setw(9) << std::left << lastname << ' ' << message
- << '\n';
+ << std::setw(9) << std::left << lastname << ' ' << message << '\n';
std::cout.flags(flags);
}
}
bool LoggingServerI::isSubpathOf(std::string const &path,
- std::string const &subpath)
+ std::string const &subpath)
{
// if path begins with subpath
if (path.compare(0, subpath.size(), subpath) == 0)
@@ -124,11 +151,11 @@ bool LoggingServerI::isSubpathOf(std::string const &path,
// <prefix>.logger.<name>=level
void LoggingServerI::configure(Ice::PropertiesPtr props)
{
- Ice::PropertyDict myProps =
- props->getPropertiesForPrefix(LoggingPropertyPrefix);
+ Ice::PropertyDict myProps = props->getPropertiesForPrefix(
+ LoggingPropertyPrefix);
for (Ice::PropertyDict::const_iterator i = myProps.begin(); i
- != myProps.end(); ++i)
+ != myProps.end(); ++i)
{
if (i->first == RootLoggerProperty)
{
diff --git a/server/src/LoggingServer.h b/server/src/LoggingServer.h
index b4e2255..c7427e9 100644
--- a/server/src/LoggingServer.h
+++ b/server/src/LoggingServer.h
@@ -53,13 +53,15 @@ private:
class LoggingServerI : public LoggingServer
{
public:
- LoggingServerI()
- {
- sources[""] = SourceNode();
- }
+ LoggingServerI();
void logs(std::string const &, Level, const std::string&,
const Ice::Current&) const;
+ Configuration getConfiguration(Ice::Current const &) const
+ {
+ return getConfiguration();
+ }
+ Configuration getConfiguration() const;
bool isEnabledFor(std::string const &name, Level level) const;
Level getEffectiveLevel(std::string const &name) const;
diff --git a/server/test/LoggingServer-test.cpp b/server/test/LoggingServer-test.cpp
index 7dd15da..3b85579 100644
--- a/server/test/LoggingServer-test.cpp
+++ b/server/test/LoggingServer-test.cpp
@@ -64,4 +64,25 @@ BOOST_AUTO_TEST_CASE(testReal)
BOOST_CHECK_EQUAL(Info, uut.getEffectiveLevel("AsteriskSCF.SessionCommunications"));
}
+BOOST_AUTO_TEST_CASE(testGetConfiguration)
+{
+ LoggingServerI uut;
+
+ uut.setLevel("", Error);
+ uut.setLevel("AsteriskSCF.Core", Debug);
+ uut.setLevel("AsteriskSCF.Media", Off);
+ uut.setLevel("AsteriskSCF", Info);
+
+ Configuration c = uut.getConfiguration();
+
+ BOOST_CHECK_EQUAL(std::string(""), c.sourceSettings[0].name);
+ BOOST_CHECK_EQUAL(Error, c.sourceSettings[0].logLevel);
+ BOOST_CHECK_EQUAL(std::string("AsteriskSCF"), c.sourceSettings[1].name);
+ BOOST_CHECK_EQUAL(Info, c.sourceSettings[1].logLevel);
+ BOOST_CHECK_EQUAL(std::string("AsteriskSCF.Core"), c.sourceSettings[2].name);
+ BOOST_CHECK_EQUAL(Debug, c.sourceSettings[2].logLevel);
+ BOOST_CHECK_EQUAL(std::string("AsteriskSCF.Media"), c.sourceSettings[3].name);
+ BOOST_CHECK_EQUAL(Off, c.sourceSettings[3].logLevel);
+}
+
BOOST_AUTO_TEST_SUITE_END()
-----------------------------------------------------------------------
--
asterisk-scf/integration/logger.git
More information about the asterisk-scf-commits
mailing list