Ack for all the patches. Tested the logger utility file. The patch related to packaging the log directory needs to be re-generated because of #1441 fix ( clm python bindings). Minor comment inline.
----- johan.o.martens...@ericsson.com wrote: > Makefile.common | 1 + > configure.ac | 1 + > opensaf.spec.in | 3 + > python/pyosaf/utils/Makefile.am | 4 +- > python/pyosaf/utils/log/Makefile.am | 23 +++++++++++ > python/pyosaf/utils/log/__init__.py | 38 ++++++++++++++++++ > python/pyosaf/utils/log/logger.py | 76 > +++++++++++++++++++++++++++++++++++++ > python/samples/amf_demo | 63 > +----------------------------- > python/samples/immadm | 4 +- > python/samples/immbase.py | 43 -------------------- > 10 files changed, 151 insertions(+), 105 deletions(-) > > > Merge the almost identical LOG convenience classes in python/samples > and extract into a new log utils class, and update the sample > applications to use it. > > Also add decorated saLog* functions on top of the direct Python > bindings for LOG and use them in the convenience class. > > diff --git a/Makefile.common b/Makefile.common > --- a/Makefile.common > +++ b/Makefile.common > @@ -37,3 +37,4 @@ lockdir = $(localstatedir)/lock/subsys > pkgpyosafdir = $(pythondir)/pyosaf > pkgpyosafutilsdir = $(pythondir)/pyosaf/utils > pkgpyosafutilsimmomdir = $(pythondir)/pyosaf/utils/immom > +pkgpyosafutilslogdir = $(pythondir)/pyosaf/utils/log > diff --git a/configure.ac b/configure.ac > --- a/configure.ac > +++ b/configure.ac > @@ -679,6 +679,7 @@ AC_CONFIG_FILES([ > python/pyosaf/Makefile > python/pyosaf/utils/Makefile > python/pyosaf/utils/immom/Makefile > + python/pyosaf/utils/log/Makefile > osaf/Makefile > osaf/libs/Makefile > osaf/libs/agents/Makefile > diff --git a/opensaf.spec.in b/opensaf.spec.in > --- a/opensaf.spec.in > +++ b/opensaf.spec.in > @@ -1516,6 +1516,9 @@ fi > %{python_sitelib}/pyosaf/utils/immom/*.py > %{python_sitelib}/pyosaf/utils/immom/*.pyc > %{python_sitelib}/pyosaf/utils/immom/*.pyo > +%{python_sitelib}/pyosaf/utils/log/*.py > +%{python_sitelib}/pyosaf/utils/log/*.pyc > +%{python_sitelib}/pyosaf/utils/log/*.pyo > %endif > > > diff --git a/python/pyosaf/utils/Makefile.am > b/python/pyosaf/utils/Makefile.am > --- a/python/pyosaf/utils/Makefile.am > +++ b/python/pyosaf/utils/Makefile.am > @@ -21,4 +21,6 @@ MAINTAINERCLEANFILES = Makefile.in > pkgpyosafutils_PYTHON = \ > __init__.py > > -SUBDIRS = immom > +SUBDIRS = \ > + immom \ > + log > diff --git a/python/pyosaf/utils/log/Makefile.am > b/python/pyosaf/utils/log/Makefile.am > new file mode 100644 > --- /dev/null > +++ b/python/pyosaf/utils/log/Makefile.am > @@ -0,0 +1,23 @@ > +# -*- OpenSAF -*- > +# > +# (C) Copyright 2011 The OpenSAF Foundation > +# > +# This program is distributed in the hope that it will be useful, > but > +# WITHOUT ANY WARRANTY; without even the implied warranty of > MERCHANTABILITY > +# or FITNESS FOR A PARTICULAR PURPOSE. This file and program are > licensed > +# under the GNU Lesser General Public License Version 2.1, February > 1999. > +# The complete license can be accessed from the following location: > +# http://opensource.org/licenses/lgpl-license.php > +# See the Copying file included with the OpenSAF distribution for > full > +# licensing terms. > +# > +# Author(s): Oracle > +# > + > +include $(top_srcdir)/Makefile.common > + > +MAINTAINERCLEANFILES = Makefile.in > + > +pkgpyosafutilslog_PYTHON = \ > + __init__.py \ > + logger.py > diff --git a/python/pyosaf/utils/log/__init__.py > b/python/pyosaf/utils/log/__init__.py > new file mode 100644 > --- /dev/null > +++ b/python/pyosaf/utils/log/__init__.py > @@ -0,0 +1,38 @@ > +############################################################################ > +# > +# (C) Copyright 2015 The OpenSAF Foundation > +# > +# This program is distributed in the hope that it will be useful, > but > +# WITHOUT ANY WARRANTY; without even the implied warranty of > MERCHANTABILITY > +# or FITNESS FOR A PARTICULAR PURPOSE. This file and program are > licensed > +# under the GNU Lesser General Public License Version 2.1, February > 1999. > +# The complete license can be accessed from the following location: > +# http://opensource.org/licenses/lgpl-license.php > +# See the Copying file included with the OpenSAF distribution for > full > +# licensing terms. > +# > +# Author(s): Ericsson > +# > +############################################################################ > + > +''' > + LOG common utilitites > +''' > +from pyosaf import saLog, saAis > + > +from pyosaf.utils import decorate > + > +LOG_VERSION = saAis.SaVersionT('A', 2, 1) > + > +# Decorate LOG functions to add retry loops and error handling > +saLogInitialize = decorate(saLog.saLogInitialize) > +saLogSelectionObjectGet = decorate(saLog.saLogSelectionObjectGet) > +saLogDispatch = decorate(saLog.saLogDispatch) > +saLogFinalize = decorate(saLog.saLogFinalize) > +saLogStreamOpen_2 = decorate(saLog.saLogStreamOpen_2) > +saLogStreamOpenAsync_2 = decorate(saLog.saLogStreamOpenAsync_2) > +saLogWriteLog = decorate(saLog.saLogWriteLog) > +saLogWriteLogAsync = decorate(saLog.saLogWriteLogAsync) > +saLogStreamClose = decorate(saLog.saLogStreamClose) > +saLogLimitGet = decorate(saLog.saLogLimitGet) > + > diff --git a/python/pyosaf/utils/log/logger.py > b/python/pyosaf/utils/log/logger.py > new file mode 100644 > --- /dev/null > +++ b/python/pyosaf/utils/log/logger.py > @@ -0,0 +1,76 @@ > +############################################################################ > +# > +# (C) Copyright 2015 The OpenSAF Foundation > +# > +# This program is distributed in the hope that it will be useful, > but > +# WITHOUT ANY WARRANTY; without even the implied warranty of > MERCHANTABILITY > +# or FITNESS FOR A PARTICULAR PURPOSE. This file and program are > licensed > +# under the GNU Lesser General Public License Version 2.1, February > 1999. > +# The complete license can be accessed from the following location: > +# http://opensource.org/licenses/lgpl-license.php > +# See the Copying file included with the OpenSAF distribution for > full > +# licensing terms. > +# > +# Author(s): Ericsson > +# > +############################################################################ > + > +import ctypes > + > +from pyosaf import saLog, saAis > +from pyosaf.utils import log > + > +# Logger class to encapsulate LOG handling > +class SafLogger(object): > + > + @staticmethod > + def writeLogCallback(invocation, error): > + pass > + > + def __init__(self, exec_name=""): > + self.invocation = 0 > + self.logHandle = saLog.SaLogHandleT() > + self.fd = saAis.SaSelectionObjectT() > + self.callbacks = saLog.SaLogCallbacksT() > + self.streamHandle = saLog.SaLogStreamHandleT() > + self.record = saLog.SaLogRecordT() > + > + self.callbacks.saLogWriteLogCallback = \ > + saLog.SaLogWriteLogCallbackT(self.writeLogCallback) > + > + log.saLogInitialize(self.logHandle, self.callbacks, > log.LOG_VERSION) > + log.saLogSelectionObjectGet(self.logHandle, self.fd) > + > + streamName = saAis.SaNameT(saLog.saLog.SA_LOG_STREAM_SYSTEM) > + log.saLogStreamOpen_2(self.logHandle, streamName, > None, 0, > + saAis.saAis.SA_TIME_ONE_SECOND, > self.streamHandle) > + > + userName = ctypes.pointer(saAis.SaNameT(exec_name)) > + headerType = saLog.eSaLogHeaderTypeT.SA_LOG_GENERIC_HEADER > + self.record.logTimeStamp = saAis.saAis.SA_TIME_UNKNOWN > + self.record.logHdrType = headerType > + self.record.logHeader.genericHdr.logSvcUsrName = userName > + > + def finalize(self): > + log.saLogStreamClose(self.streamHandle) > + log.saLogFinalize(self.logHandle) > + > + def get_invocation(self): > + self.invocation += 1 > + return self.invocation > + > + def __del__(self): > + self.finalize() > + > + def log(self, logstr): > + log_buffer = ctypes.pointer(saLog.SaLogBufferT(logstr)) > + notice = saLog.SA_LOG_SEV_NOTICE > + self.record.logBuffer = log_buffer > + self.record.logHeader.genericHdr.logSeverity = notice > + log.saLogWriteLogAsync(self.streamHandle, > + self.get_invocation(), > + saLog.SA_LOG_RECORD_WRITE_ACK, > self.record) > + > + def dispatch(self, readfds): > + if self.fd.value in readfds: > + log.saLogDispatch(self.logHandle, > saAis.eSaDispatchFlagsT.SA_DISPATCH_ALL) > diff --git a/python/samples/amf_demo b/python/samples/amf_demo > --- a/python/samples/amf_demo > +++ b/python/samples/amf_demo > @@ -16,6 +16,8 @@ > # > > ############################################################################ > > +from pyosaf.utils import log > +from pyosaf.utils.log.logger import SafLogger > from pyosaf.saAmf import * > from pyosaf.saLog import * > import select > @@ -29,65 +31,6 @@ def chexit(funcName, rc): > errstr = '%s FAILED (%s)!' % (funcName, eSaAisErrorT.whatis(rc)) > raise ValueError(errstr) > > -class LogIface(object): > - @staticmethod > - def writeLogCallback(invocation, error): > - pass > - > - def __init__(self): > - self.invocation = 0 > - self.logHandle = SaLogHandleT() > - self.fd = SaSelectionObjectT() > - self.callbacks = SaLogCallbacksT() > - self.streamHandle = SaLogStreamHandleT() > - self.record = SaLogRecordT() > - > - self.callbacks.saLogWriteLogCallback = \ > - SaLogWriteLogCallbackT(self.writeLogCallback) > - > - logVersion = SaVersionT('A', 2, 1) > - chexit('saLogInitialize', > - saLogInitialize(self.logHandle, self.callbacks, > - logVersion)) > - chexit('saLogSelectionObjectGet', > - saLogSelectionObjectGet(self.logHandle, > - self.fd)) > - > - streamName = SaNameT(saLog.SA_LOG_STREAM_SYSTEM) > - chexit('saLogStreamOpen_2', > - saLogStreamOpen_2(self.logHandle, streamName, None, 0, > - saAis.SA_TIME_ONE_SECOND, self.streamHandle)) > - > - userName = pointer(SaNameT(exec_name)) > - headerType = eSaLogHeaderTypeT.SA_LOG_GENERIC_HEADER > - self.record.logTimeStamp = saAis.SA_TIME_UNKNOWN > - self.record.logHdrType = headerType > - self.record.logHeader.genericHdr.logSvcUsrName = userName > - > - def finalize(self): > - saLogStreamClose(self.streamHandle) > - saLogFinalize(self.logHandle) > - > - def get_invocation(self): > - self.invocation += 1 > - return self.invocation > - > - def log(self, logstr): > - buffer = pointer(SaLogBufferT(logstr)) > - notice = saLog.SA_LOG_SEV_NOTICE > - self.record.logBuffer = buffer > - self.record.logHeader.genericHdr.logSeverity = notice [ Srikanth ] : The severity value can be read as default parameter, such a way that user can either go for other severity values like CRITICAL/ ERROR etc or otherwise the default value NOTICE. Thanks, Srikanth > - chexit('saLogWriteLogAsync', > - saLogWriteLogAsync(self.streamHandle, > - self.get_invocation(), > - saLog.SA_LOG_RECORD_WRITE_ACK, self.record)) > - > - def dispatch(self, readfds): > - if self.fd.value in readfds: > - chexit('saLogDispatch', > - saLogDispatch(self.logHandle, > - eSaDispatchFlagsT.SA_DISPATCH_ALL)) > - > class AmfIface(object): > @staticmethod > def log(logstr): > @@ -213,7 +156,7 @@ class AmfIface(object): > eSaDispatchFlagsT.SA_DISPATCH_ALL)) > > def main(): > - logger = LogIface() > + logger = SafLogger() > AmfIface.initialize(logger) > > readfds = [logger.fd.value, AmfIface.fd.value] > diff --git a/python/samples/immadm b/python/samples/immadm > --- a/python/samples/immadm > +++ b/python/samples/immadm > @@ -24,6 +24,8 @@ from immbase import * > import json > import sys > > +from pyosaf.utils.log.logger import SafLogger > + > def getExecName(): > return ':'.join((gethostname(), sys.argv[0], str(getpid()))) > > @@ -103,6 +105,6 @@ def immadm(options, args): > if __name__ == '__main__': > (options, args) = parseArgs() > result = immadm(options, args) > - logger = LogIface(result['owner']) > + logger = SafLogger(result['owner']) > logger.log('ADMIN_CMD: OP_ID %(opId)s %(dname)s: %(rc)s' % result) > print json.dumps(result, indent=None if options.ugly else 4) > diff --git a/python/samples/immbase.py b/python/samples/immbase.py > --- a/python/samples/immbase.py > +++ b/python/samples/immbase.py > @@ -17,10 +17,8 @@ > > from pyosaf.saImmOm import * > from pyosaf.saAmf import * > -from pyosaf.saLog import * > > IMM_VERSION = SaVersionT('A', 2, 1) > -LOG_VERSION = SaVersionT('A', 2, 1) > > class SafException(Exception): > def __init__(self, value): > @@ -90,44 +88,3 @@ class SafObject(object): > ] > if not numeric: > SafObject.resolveStates(self.attribs) > - > -class LogIface(object): > - @staticmethod > - def writeLogCallback(invocation, error): > - pass > - > - def __init__(self, execName): > - self.invocation = 0 > - self.logHandle = SaLogHandleT() > - self.callbacks = SaLogCallbacksT() > - self.streamHandle = SaLogStreamHandleT() > - self.record = SaLogRecordT() > - self.callbacks.saLogWriteLogCallback = \ > - SaLogWriteLogCallbackT(self.writeLogCallback) > - rc = saLogInitialize(self.logHandle, self.callbacks, > LOG_VERSION) > - if rc != eSaAisErrorT.SA_AIS_OK: > - raise SafException(rc) > - streamName = SaNameT(saLog.SA_LOG_STREAM_SYSTEM) > - rc = saLogStreamOpen_2(self.logHandle, streamName, None, 0, > - saAis.SA_TIME_ONE_SECOND, self.streamHandle) > - if rc != eSaAisErrorT.SA_AIS_OK: > - raise SafException(rc) > - userName = pointer(SaNameT(execName)) > - headerType = eSaLogHeaderTypeT.SA_LOG_GENERIC_HEADER > - self.record.logTimeStamp = saAis.SA_TIME_UNKNOWN > - self.record.logHdrType = headerType > - self.record.logHeader.genericHdr.logSvcUsrName = userName > - > - def __del__(self): > - saLogStreamClose(self.streamHandle) > - saLogFinalize(self.logHandle) > - > - def log(self, logstr): > - buffer = pointer(SaLogBufferT(logstr)) > - notice = saLog.SA_LOG_SEV_NOTICE > - self.record.logBuffer = buffer > - self.record.logHeader.genericHdr.logSeverity = notice > - rc = saLogWriteLogAsync(self.streamHandle, 0, > - saLog.SA_LOG_RECORD_WRITE_ACK, self.record) > - if rc != eSaAisErrorT.SA_AIS_OK: > - raise SafException(rc) ------------------------------------------------------------------------------ _______________________________________________ Opensaf-devel mailing list Opensaf-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensaf-devel