[asterisk-scf-commits] asterisk-scf/release/logger.git branch "master" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Thu Sep 22 12:59:16 CDT 2011
branch "master" has been updated
via 2f13e1c4e013cc20d3672df8029502c6836613c1 (commit)
from 8b3d9fc03b820e35cc859a05fbd246b930ce6237 (commit)
Summary of changes:
server/config/Logger.config | 62 ++++++++++++
server/config/LoggerConfigurator.py | 99 ++++++++++++++++++++
server/src/Configuration.cpp | 4 -
server/src/FileChainedLogOut.cpp | 4 +-
server/src/main.cpp | 23 +++--
.../LoggingService/LoggingConfigurationIf.ice | 12 +-
6 files changed, 182 insertions(+), 22 deletions(-)
create mode 100644 server/config/Logger.config
create mode 100644 server/config/LoggerConfigurator.py
- Log -----------------------------------------------------------------
commit 2f13e1c4e013cc20d3672df8029502c6836613c1
Author: Ken Hunt <ken.hunt at digium.com>
Date: Thu Sep 22 12:59:08 2011 -0500
Added configurator and sample config file for logger.
diff --git a/server/config/Logger.config b/server/config/Logger.config
new file mode 100644
index 0000000..251a82a
--- /dev/null
+++ b/server/config/Logger.config
@@ -0,0 +1,62 @@
+
+[general]
+
+# Logging level.
+# This is an array of level item values.
+# Each level item contains a logging level, and a logger name param.
+# A comma sepatates the params, and semi-colon each item.
+#
+# @param level The valid levels are (in increasing levels of verbosity):
+# Emergency, Alert, Critical, Error, Warning, Notice, Info, Debug, Trace
+#
+# @param loggerName The logger names are defined by each component. If
+# the name is empty (i.e. ""), sets the default log level.
+#
+# Component logger names:
+# "AsteriskSCF.BasicRoutingService"
+# "AsteriskSCF.BasicRoutingServiceStateReplicator"
+# "AsteriskSCF.BridgeService"
+# "AsteriskSCF.BridgeReplicator"
+# "AsteriskSCF.MediaOperationsCore"
+# "AsteriskSCF.MediaOperationStateReplicator"
+# "AsteriskSCF.MediaRTP"
+# "AsteriskSCF.MediaFormatGeneric"
+# "SipSessionGateway"
+# "SipSessionGatewayReplicator"
+# "AsteriskSCF.System.Discovery"
+#
+# In this example, the default logging level is set to Debug,
+# the RoutingService output level is decreased to Info.
+# Example:
+# levels= Debug,"";Info,"AsteriskSCF.BasicRoutingService"
+#
+
+levels= Debug,""
+
+# Filename for logging output
+
+filename = "logout.txt"
+
+# The format string is composed of format parameters and other text, much like
+# the printf statement. Valid format parameters are:
+#
+# $m - the message to log. You always want this one in your format string.
+# $n - the name of the logger
+# $l - the level of the message being logged
+# $h - the client host name
+# $t - current time, can be further formatted with additional specifiers following the
+# boost::posix_time::time_facet format, which is similar to the strftime() format.
+# The additional specifiers should be in a set of curly braces,
+# like: $t{%x %X} would format the time into a date/time string. If no additional
+# format specifiers are given (ie, just $t), the system uses the default
+# time format.
+# $p - current process id
+# $C - component category. This is part of the Service Locator params for the Component
+# Service for the component performing the logging.
+# $S - service name. This is part of the Service Locator params for the Component
+# Service for the component performing the logging.
+# $I - component instance id. This is part of the Service Locator params for the Component
+# Service for the component performing the logging.
+
+format="$n($l): $m @ $t (from $I)"
+
diff --git a/server/config/LoggerConfigurator.py b/server/config/LoggerConfigurator.py
new file mode 100644
index 0000000..26251cb
--- /dev/null
+++ b/server/config/LoggerConfigurator.py
@@ -0,0 +1,99 @@
+#!/usr/bin/env python
+
+#
+# Asterisk SCF -- An open-source communications framework.
+#
+# Copyright (C) 2011, Digium, Inc.
+#
+# See http://www.asterisk.org for more information about
+# the Asterisk SCF project. Please do not directly contact
+# any of the maintainers of this project for assistance;
+# the project provides a web site, mailing lists and IRC
+# channels for your use.
+#
+# This program is free software, distributed under the terms of
+# the GNU General Public License Version 2. See the LICENSE.txt file
+# at the top of the source tree.
+#
+
+# Bring in the common configuration infrastructure
+import ConfigParser, Ice, Configurator, sys, os
+
+# Load our component specific configuration definitions
+Ice.loadSlice("-I\"" + os.environ["ASTSCF_HOME"] + "\" -I\"" + Ice.getSliceDir() + "\" --all LoggingConfigurationIf.ice")
+import AsteriskSCF.Configuration.LoggingService.V1
+
+# Add our own visitor implementations for the sections we support
+class LoggingServiceSectionVisitors(Configurator.SectionVisitors):
+
+ def getLevel(self, levelName):
+ levelName = levelName.strip()
+ if levelName == 'Trace':
+ return AsteriskSCF.System.Logging.Level.Trace
+ elif levelName == 'Debug':
+ return AsteriskSCF.System.Logging.Level.Debug
+ elif levelName == 'Info':
+ return AsteriskSCF.System.Logging.Level.Info
+ elif levelName == 'Notice':
+ return AsteriskSCF.System.Logging.Level.Notice
+ elif levelName == 'Warning':
+ return AsteriskSCF.System.Logging.Level.Warning
+ elif levelName == 'Error':
+ return AsteriskSCF.System.Logging.Level.Error
+ elif levelName == 'Critical':
+ return AsteriskSCF.System.Logging.Level.Critical
+ elif levelName == 'Alert':
+ return AsteriskSCF.System.Logging.Level.Alert
+ elif levelName == 'Emergency':
+ return AsteriskSCF.System.Logging.Level.Emergency
+ elif levelName == 'Off':
+ return AsteriskSCF.System.Logging.Level.Off
+ print "Level identifier " + levelName + " is unknown. Defaulting to Debug"
+ return AsteriskSCF.System.Logging.Level.Debug
+
+ def visit_general(self, config, section):
+ group = AsteriskSCF.Configuration.LoggingService.V1.LoggerGeneralGroup()
+ group.name = section
+ group.configurationItems = { }
+
+ mapper = Configurator.OptionMapper()
+
+ try:
+ levels = config.get(section, 'levels')
+ levelsList = levels.split(';')
+ levelItemCount = 0
+ for levelSpec in levelsList:
+ levelParts = levelSpec.split(',')
+ logLevel = self.getLevel(levelParts[0])
+ loggerName = levelParts[1]
+# print "logLevel = {0} and loggerName = {1}".format(logLevel, loggerName)
+ levelItem = AsteriskSCF.Configuration.LoggingService.V1.LevelItem()
+
+ levelItem.loggingLevel = logLevel
+ levelItem.loggerName = loggerName
+ group.configurationItems['loggingLevel' + `levelItemCount`] = levelItem
+ levelItemCount = levelItemCount + 1
+ except ConfigParser.NoOptionError:
+ pass
+
+ fileItem = AsteriskSCF.Configuration.LoggingService.V1.FileItem()
+ mapper.map('filename', fileItem, 'fileName', 'filename', config.get, None)
+
+ formatItem = AsteriskSCF.Configuration.LoggingService.V1.FormatItem()
+ mapper.map('format', formatItem, 'formatSpec', 'format', config.get, None)
+
+ for option in config.options(section):
+ mapper.execute(group, section, option)
+
+ mapper.finish(group)
+
+ self.groups.append(group)
+
+# In order to do service locator based lookup we need to pass in a params object
+serviceLocatorParams = AsteriskSCF.Core.Discovery.V1.ServiceLocatorParams()
+serviceLocatorParams.category = AsteriskSCF.Configuration.LoggingService.V1.ConfigurationDiscoveryCategory
+serviceLocatorParams.service = 'default'
+
+# Make a configurator application and let it run
+app = Configurator.ConfiguratorApp('Logger.config', LoggingServiceSectionVisitors(), None, serviceLocatorParams)
+sys.exit(app.main(sys.argv))
diff --git a/server/src/Configuration.cpp b/server/src/Configuration.cpp
index aabf7a6..eb3ed8b 100644
--- a/server/src/Configuration.cpp
+++ b/server/src/Configuration.cpp
@@ -55,7 +55,6 @@ public:
FormatItemI(const LoggingServerIPtr& server, const std::string& fmt)
: mServer(server)
{
- printf("FormatItem constructor, this = %p\n",this);
formatSpec = fmt;
mServer->setFormat(fmt);
}
@@ -74,7 +73,6 @@ public:
LevelItemI(const LoggingServerIPtr& server, const std::string& name, const Level level)
: mServer(server), mName(name)
{
- printf("LevelItem constructor, this = %p\n",this);
mServer->setLevel(name, level);
}
~LevelItemI()
@@ -292,9 +290,7 @@ void LoggerConfigurationService::setConfiguration(const ConfigurationGroupSeq& g
}
void visitFormatItem(const FormatItemPtr& formatItem)
{
- printf("Calling format constructor\n");
mPriv->mGeneralConfiguration->mFormat = new FormatItemI(mPriv->mServer, formatItem->formatSpec);
- printf("Back from calling format constructor\n");
}
void visitLevelItem(const LevelItemPtr &levelItem)
{
diff --git a/server/src/FileChainedLogOut.cpp b/server/src/FileChainedLogOut.cpp
index 5c26433..ad9abd9 100644
--- a/server/src/FileChainedLogOut.cpp
+++ b/server/src/FileChainedLogOut.cpp
@@ -13,7 +13,7 @@
* the GNU General Public License Version 2. See the LICENSE.txt file
* at the top of the source tree.
*/
-
+#include <fstream>
#include <IceUtil/IceUtil.h>
#include "FileChainedLogOut.h"
@@ -33,7 +33,7 @@ void FileChainedLogOut::myLogs(const std::string& name, Level logLevel,
if (!mOut || !mOut.is_open())
{
// reopen the file
- mOut.open(mLogFile.c_str());
+ mOut.open(mLogFile.c_str(), std::ios::out);
}
if (mOut && mOut.is_open())
diff --git a/server/src/main.cpp b/server/src/main.cpp
index 18bf604..e258ec5 100644
--- a/server/src/main.cpp
+++ b/server/src/main.cpp
@@ -44,22 +44,21 @@ protected:
private:
Ice::ObjectAdapterPtr mAdapter;
ServiceManagementPrx mServiceManagement;
+ LoggingServerPrx mServerPrx;
+
ServiceManagementPrx mConfigManagement;
ConfigurationServicePtr mConfigurationService;
ConfigurationServicePrx mConfigurationServicePrx;
std::string mName;
- void registerWithServiceLocator(const Ice::CommunicatorPtr& communicator,
- const LoggingServerPrx& serverProxy);
+ void registerWithServiceLocator(const Ice::CommunicatorPtr& communicator);
void setupDefaultProperties(const Ice::CommunicatorPtr& communicator);
void setDefaultProperty(Ice::Properties& properties, const std::string& key,
const std::string& defaultValue);
};
}
-void LoggingService::registerWithServiceLocator(
- const Ice::CommunicatorPtr& communicator,
- const LoggingServerPrx& serverProxy)
+void LoggingService::registerWithServiceLocator(const Ice::CommunicatorPtr& communicator)
{
try
{
@@ -76,7 +75,8 @@ void LoggingService::registerWithServiceLocator(
ServiceLocatorManagementPrx::checkedCast(
communicator->stringToProxy(locatorManagementProxyString));
- mServiceManagement = management->addService(serverProxy,
+ {
+ mServiceManagement = management->addService(mServerPrx,
mName + "." + LoggingServerGuid);
ServiceLocatorParamsPtr params(new ServiceLocatorParams);
@@ -84,9 +84,11 @@ void LoggingService::registerWithServiceLocator(
params->service = serviceName;
params->id = mName;
mServiceManagement->addLocatorParams(params, "");
+ }
// Do the same for the configuration interface.
- mConfigManagement = management->addService(serverProxy,
+ {
+ mConfigManagement = management->addService(mConfigurationServicePrx,
IceUtil::generateUUID());
ServiceLocatorParamsPtr configParams(new ServiceLocatorParams);
@@ -94,6 +96,7 @@ void LoggingService::registerWithServiceLocator(
configParams->service = serviceName;
configParams->id = mName;
mConfigManagement->addLocatorParams(configParams, "");
+ }
}
else
{
@@ -187,7 +190,7 @@ void LoggingService::start(const std::string& name,
server->configure(configurationListener,
communicator->getProperties());
- LoggingServerPrx serverProxy = LoggingServerPrx::uncheckedCast(
+ mServerPrx = LoggingServerPrx::uncheckedCast(
mAdapter->addWithUUID(server));
mConfigurationService = new LoggerConfigurationService(server);
@@ -196,8 +199,8 @@ void LoggingService::start(const std::string& name,
mAdapter->activate();
- std::cout << serverProxy->ice_toString() << '\n';
- registerWithServiceLocator(communicator, serverProxy);
+ std::cout << mServerPrx->ice_toString() << '\n';
+ registerWithServiceLocator(communicator);
}
void LoggingService::stop()
diff --git a/slice/AsteriskSCF/Configuration/LoggingService/LoggingConfigurationIf.ice b/slice/AsteriskSCF/Configuration/LoggingService/LoggingConfigurationIf.ice
index 955c770..7034412 100644
--- a/slice/AsteriskSCF/Configuration/LoggingService/LoggingConfigurationIf.ice
+++ b/slice/AsteriskSCF/Configuration/LoggingService/LoggingConfigurationIf.ice
@@ -53,7 +53,7 @@ module V1
/**
* General Logger configuration group that contains general items related to the Logger component as a whole
*/
- unsliceable class LoggerGeneralGroup extends LoggerConfigurationGroup
+ class LoggerGeneralGroup extends LoggerConfigurationGroup
{
};
@@ -63,19 +63,19 @@ module V1
local class LoggerConfigurationItemVisitor extends AsteriskSCF::System::Configuration::V1::ConfigurationItemVisitor
{
};
-
+
/**
* Generic Logger configuration item
*/
["visitor:LoggerConfigurationItemVisitor"]
- unsliceable class LoggerConfigurationItem extends AsteriskSCF::System::Configuration::V1::ConfigurationItem
+ class LoggerConfigurationItem extends AsteriskSCF::System::Configuration::V1::ConfigurationItem
{
};
/**
* ConfigurationItem that describes an output file to which logger output should be sent
*/
- unsliceable class FileItem extends LoggerConfigurationItem
+ class FileItem extends LoggerConfigurationItem
{
/**
* The name of the file to send output to
@@ -86,7 +86,7 @@ module V1
/**
* ConfigurationItem that describes the logger's output level.
*/
- unsliceable class LevelItem extends LoggerConfigurationItem
+ class LevelItem extends LoggerConfigurationItem
{
/**
* Name of the logger to set the level for.
@@ -104,7 +104,7 @@ module V1
/**
* ConfigurationItem that describes a format string the logger will use in preparing messages
*/
- unsliceable class FormatItem extends LoggerConfigurationItem
+ class FormatItem extends LoggerConfigurationItem
{
/**
* String describing the logger format.
-----------------------------------------------------------------------
--
asterisk-scf/release/logger.git
More information about the asterisk-scf-commits
mailing list