OpenClovis Logo

API Usage Examples

Code Examples.

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.
}
ClUint32T ClRcT
Clovis return code type.
Definition: clCommon.h:168
#define CL_OK
Every thing is OK.
Definition: clCommonErrors.h:68
#define CL_HANDLE_INVALID_VALUE
Defines.
Definition: clHandleApi.h:95
ClPtrT clHeapCalloc(CL_IN ClUint32T numChunks, CL_IN ClUint32T chunkSize)
Allocates memory for an array and initializes it to zero.
#define CL_LOG_STREAM_CREATE
This flag specifies the log service that the particular stream should be created, if it does not exis...
Definition: clLogApi.h:181
#define CL_LOG_MSGID_BUFFER
Logging messgae in binary format.
Definition: clLogApi.h:568
ClRcT clLogFinalize(CL_IN ClLogHandleT hLog)
Finalize the Log service for the calling process and ensures to release all the resources.
ClRcT clLogFilterSet(CL_IN ClLogStreamHandleT hStream, CL_IN ClLogFilterFlagsT filterFlags, CL_IN ClLogFilterT filter)
Changes the filter settings of a Log Stream.
#define CL_LOG_TLV_UINT32(var)
TLV for unsigned 32 bit varible(ClUint32T).
Definition: clLogApi.h:626
ClLogSeverityT
Definition: clLogApi.h:252
ClHandleT ClLogHandleT
The type of handle supplied by Log Service during initialization.
Definition: clLogApi.h:57
ClRcT clLogStreamOpen(CL_IN ClLogHandleT hLog, CL_IN ClNameT streamName, CL_IN ClLogStreamScopeT streamScope, CL_IN ClLogStreamAttributesT *pStreamAttr, CL_IN ClLogStreamOpenFlagsT streamOpenFlags, CL_IN ClTimeT timeout, CL_OUT ClLogStreamHandleT *phStream)
Opens the stream for Logging.
#define CL_LOG_TAG_TERMINATE
This tag is used for terminating the TLV type.
Definition: clLogApi.h:578
ClRcT clLogInitialize(CL_OUT ClLogHandleT *phLog, CL_IN const ClLogCallbacksT *pLogCallbacks, CL_INOUT ClVersionT *pVersion)
Initializes the Log service for the calling process and ensures the version compatability.
#define CL_LOG_MSGID_PRINTF_FMT
Logging message in ASCII format.
Definition: clLogApi.h:573
ClHandleT ClLogStreamHandleT
The type of handle supplied by Log Service during log streamOpen and a process register itself as str...
Definition: clLogApi.h:63
ClRcT clLogStreamClose(CL_IN ClLogStreamHandleT hStream)
Close the stream opened for logging.
ClRcT clLogWriteAsync(ClLogStreamHandleT hStream, ClLogSeverityT severity, ClUint16T serviceId, ClUint16T msgId,...)
Logs a Log Record in the specified Log Stream.
#define CL_LOG_FILTER_ASSIGN
Discard the old filter settings and use new settings provided.
Definition: clLogApi.h:357
#define CL_LOG_TLV_UINT8(var)
TLV for unsigned byte variable(ClUint8T).
Definition: clLogApi.h:602
@ CL_LOG_SEV_ALERT
setting severity as ALERT.
Definition: clLogApi.h:260
@ CL_LOG_STREAM_GLOBAL
Flags specifies the streams global to the node.
Definition: clLogApi.h:91
@ CL_LOG_FILE_FULL_ACTION_ROTATE
It directs the Log Service to create a new Log File Unit when the current Log File Unit becomes full.
Definition: clLogApi.h:111
Version Information for various services.
Definition: clCommon.h:250
This structure describes the attributes of the stream.
Definition: clLogApi.h:127
ClUint32T flushFreq
Num of log records after which the log stream records must be flushed.
Definition: clLogApi.h:160
ClTimeT flushInterval
Time after which the log stream records must be flushed.
Definition: clLogApi.h:164
ClBoolT haProperty
Log file replication property.
Definition: clLogApi.h:147
ClUint32T fileUnitSize
Size of the file unit.
Definition: clLogApi.h:139
ClLogFileFullActionT fileFullAction
Action that log service has to take, when the log file unit becomes full.
Definition: clLogApi.h:151
ClUint32T recordSize
Size of the log record.
Definition: clLogApi.h:143
ClCharT * fileLocation
Its the path where the log file unit(s) will be created.
Definition: clLogApi.h:135
ClWaterMarkT waterMark
The water mark for file units.When the size of file reaches this level, the water mark event will be ...
Definition: clLogApi.h:169
ClCharT * fileName
Its the prefix name of file units that are going to be created.
Definition: clLogApi.h:131
ClUint32T maxFilesRotated
If fileAction is CL_LOG_FILE_FULL_ACTION_ROTATE, the maximum num of log file units that will be creat...
Definition: clLogApi.h:156
This structure describes the filter settings for the stream.
Definition: clLogApi.h:379
This structure describes about the callbacks which can be provided by process while initializing with...
Definition: clLogApi.h:543
//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.");
#define clAppLog(streamHandle, severity, serviceId, area, context,...)
Logging for applications.
Definition: clLogUtilApi.h:199
@ CL_LOG_SEV_INFO
setting severity as INFORMATION.
Definition: clLogApi.h:280

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