OpenClovis Logo

API Usage Examples
Log Service

Code Examples. More...

Code Examples.

ClRcT rc = CL_OK;
ClVersionT version = {'B', 0x1, 0x1};
ClLogCallbacksT logCallbacks = {0};
// Initializes the log library.
rc = clLogInitialize(&logSvcHandle, &logCallbacks, &version);
if(CL_OK != rc)
{
// Error occured. Take appropriate action.
}
// Open a new application stream.
ClLogStreamAttributesT streamAttr = {0};
// copying the filename
if( NULL ==
( streamAttr.fileName = clHeapCalloc(1, strlen("file1")+1)))
{
/* no memory take appropriate action */
}
strcpy(streamAttr.fileName, "file1");
// Filelocation is of the following format.
// *:<absolute path> or .:<absolutepath> or <nodename>:<absolutepath>
// *:<absolute path>, this creates the file wherever system controller runs.
// .:<absolute path>, this creates the file in the local node
// <nodename>:<absolute path>, this creates the file where this node name
// instance is running
// filelocation should be existing and absolute path
if( NULL ==
( streamAttr.fileLocation = clHeapCalloc(1, strlen(".:/tmp")+1)))
{
// no memory take appropriate action
}
strcpy(streamAttr.fileLocation, ".:/tmp");
streamAttr.haProperty = 0;
streamAttr.fileUnitSize = 100 * 1024;
streamAttr.recordSize = 1024;
streamAttr.maxFilesRotated = 3;
streamAttr.flushFreq = 20;
streamAttr.flushInterval = 100000000;
streamAttr.waterMark = {0, 80};
// open or create the stream
rc = clLogStreamOpen(logSvcHandle, streamName, CL_LOG_STREAM_GLOBAL,
&streamAttr, CL_LOG_STREAM_CREATE, 0, &streamHandle);
if(CL_OK != rc)
{
// error occurred. Take appropriate action
}
// Log a message to the stream being created
// severity could be one of ClLogSeverityT, based on the criticality of
// the message.
// serviceId This field identifies the module within
// the process which is generating this Log Record. If the Log Record
// message is a generic one like out of memory, this field can be used to
// narrow down on the module impacted. For ASP client libraries, these
// values are defined in clCommon.h. For application modules, it is up-to
// the application developer to define the values and scope of those values.
// msgId could be CL_LOG_MSGID_BUFFER, CL_LOG_MSGID_PRINTF_FMT, any of the
// logger defined message-ids.
rc = clLogWriteAsync(streamHandle, severity, serviceId, msgId,
"this is the api reference guide code example");
if(CL_OK != rc)
{
// Error occured. Take appropriate action.
}
//code snippet for binary logging
ClCharT buffer[0xfff] = {0};
ClUint32T length = 0xfff;
rc = clLogWriteAsync(streamHandle, severity, serviceId, CL_LOG_MSGID_BUFFER,
length, buffer);
//code snippet for ASCII logging using this API.
rc = clLogWriteAsync(streamHandle, severity, serviceId, CL_LOG_MSGID_PRINTF_FMT,
"This is api reference guide ASCII logging");
//code snipper for TLV logging. CL_LOG_USER_DEFINED_MSGID should be defined
//by user, and it should not have values of CL_LOG_MSGID_BUFFER and
//CL_LOG_MSGID_PRINTF_FMT.
rc = clLogWriteAsync(streamHandle, severity, serviceId,
CL_LOG_USER_DEFINED_MSGID, CL_LOG_TLV_UINT8(bitVar),
// Closes a stream
rc = clLogStreamClose(streamHandle);
if(CL_OK != errorCode)
{
// Error occured. Take appropriate action.
}
// Sets the log level of an Eo to CL_LOG_ALERT
// streamFilter flags could be one of the following
// CL_LOG_FILTER_ASSIGN, CL_LOG_FILTER_MERGE, CL_LOG_FILTER_DEL
ClLogFilterT filter = { 1 << (severity - 1),
0, NULL, 0, NULL };
rc = clLogFilterSet( streamHandle, CL_LOG_FILTER_ASSIGN,
filter);
if(CL_OK != rc)
{
// Error occured. Take appropriate action.
}
// Finalizing the log library. Not doing this would lead to memory leaks.
errorCode = clLogFinalize(logSvcHandle);
if(CL_OK != rc)
{
// Error occured. Take appropriate action.
}
//The following code describes how to do ASCII logging by using clAppLog() macro.
//Here the streamHandle which we got after opening a specific stream.
//ServiceId is specific to module from which this log message is being logged.
clAppLog(streamHandle, CL_LOG_SEV_INFO, serviceId, "AREA", "CONTEXT",
"This is example messgae for ASCII logging");
//The following code describes how to log into default(perennial) streams
//supported by ASP/log service. CL_LOG_HANDLE_SYS is handle for predefined
//SYS stream. CL_LOG_HANDLE_APP is handle for predefined APP stream.
clAppLog(CL_LOG_HANDLE_SYS, CL_LOG_SEV_INFO, serviceId, "AREA", "CONTEXT",
"Logging to SYS stream by using clAppLog macro.");
clAppLog(CL_LOG_HANDLE_APP, CL_LOG_SEV_INFO, serviceId, "AREA", "CONTEXT",
"Logging to APP stream by using clAppLog macro.");

Generated on Tue Jan 10 10:29:15 PST 2012 for OpenClovis SDK using Doxygen