/* Server Eo Data Dump */
ClRcT
clLogSvrEoDataDump(ClCharT  **ret)
{
    ClRcT                rc           = CL_OK;
    ClDebugPrintHandleT  msg          = 0;
    ClLogSvrEoDataT      *pSvrEoEntry = NULL;

	CL_LOG_DEBUG_TRACE(("Enter"));

    clDebugPrintInitialize(&msg);
    
    rc = clLogSvrEoEntryGet(&pSvrEoEntry, NULL);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clLogSvrEoEntryGet(): rc[0x%x]", rc));
        return rc;
    }
    
    clDebugPrint(msg, "\nServer EO data \n");

    clDebugPrint(msg, "Cpm Handle: %llu\n", pSvrEoEntry->hCpm);

    clDebugPrint(msg, "Log Component id: %ud\n", pSvrEoEntry->logCompId);

    clDebugPrint(msg, "Handle to Server Stream table: %p\n",
                  pSvrEoEntry->hSvrStreamTable);

#ifndef __KERNEL__
    clDebugPrint(msg, "Table Lock id: %p\n", (void *) &pSvrEoEntry->svrStreamTableLock);
#else
    clDebugPrint(msg, "Table Lock id: %ud\n", &pSvrEoEntry->svrStreamTableLock);
#endif

    clDebugPrint(msg, "Next valid Dataset id: %ud\n", pSvrEoEntry->nextDsId);
    clDebugPrint(msg, "Bitmap Handle: %p\n", (void *) pSvrEoEntry->hDsIdMap);
    clDebugPrint(msg, "Water mark for flushing - limit: %u\n", pSvrEoEntry->maxFlushLimit);

    clDebugPrintFinalize(&msg, ret);
    
    CL_LOG_DEBUG_TRACE(("Exit"));
    return CL_OK;
}
ClRcT
clLogCompTableWalkForPrint(ClCntKeyHandleT   key,
                           ClCntDataHandleT  data,
                           ClCntArgHandleT   arg,
                           ClUint32T         size)
{
    ClRcT                rc        = CL_OK;
    ClLogCompKeyT        *pCompKey = (ClLogCompKeyT *) key;
    ClLogSOCompDataT            *pData    = (ClLogSOCompDataT *) data;
    ClDebugPrintHandleT  msg       = *((ClDebugPrintHandleT *) arg);
    
    CL_LOG_DEBUG_TRACE(("Enter"));
    
    clDebugPrint(msg, "NodeAddress:  %d \n", pCompKey->nodeAddr);
    clDebugPrint(msg, "CompId     :  %d \n", pCompKey->compId);
    clDebugPrint(msg, "RefCount   :  %d \n", pData->refCount);

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
static ClRcT
compTableStateRecoverBaseVersion(ClBufferHandleT msg)
{
    ClRcT rc = CL_OK;
    ClUint32T        numComps = 0;
    ClUint32T        count    = 0;
    ClLogCompDataT   compData = {{0}};
    ClInt32T readOffset = sizeof(ClUint32T);

    rc = clXdrUnmarshallClUint32T(msg, &numComps);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clXdrUnmarshallClUint32T(): rc[0x %x]", rc));
        return rc;
    }
    readOffset += sizeof(ClUint32T);
    CL_LOG_DEBUG_TRACE(("Num comps received: %d", numComps));
    for( count = 0; count < numComps; count++)
    {
        if(count > 0)
        {
            readOffset += CL_LOG_COMP_SEC_OFFSET;
            clBufferReadOffsetSet(msg, readOffset, CL_BUFFER_SEEK_SET);
        }
        rc = VDECL_VER(clXdrUnmarshallClLogCompDataT, 4, 0, 0)(msg, &compData);
        if( CL_OK != rc )
        {
            CL_LOG_DEBUG_ERROR(("clLogMarshallClLogCompDataT(): rc[0x %x]", rc));
            return rc;
        }
        rc = clLogMasterCompEntryUpdate(&compData.compName, &compData.clientId,
                                        CL_TRUE);
        if( CL_OK != rc )
        {
            CL_LOG_DEBUG_ERROR(("VDECL_VER(clLogMasterCompIdChkNGet, 4, 0, 0)(): rc[0x %x]", rc));
        }
    }

    CL_LOG_DEBUG_TRACE(("Exit"));
    return CL_OK;
}
ClRcT
clLogSvrStreamCurrentFilterGet(ClCntNodeHandleT  hStreamOwnerNode,
                               SaNameT           *pStreamName,
                               SaNameT           *pStreamNodeName,
                               ClPtrT            pStreamHeader)
{
    ClRcT              rc              = CL_OK;
    ClIdlHandleT       hStreamOwnerIdl = CL_HANDLE_INVALID_VALUE;
    ClLogStreamScopeT  streamScope     = CL_LOG_STREAM_GLOBAL;

    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clLogStreamScopeGet(pStreamNodeName, &streamScope);
    if( CL_OK != rc )
    {
        return rc;
    }
    rc = clLogSvrIdlHandleInitialize(streamScope, &hStreamOwnerIdl);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clLogSvrIdlHandleInitialize(): rc[0x %x]\n", rc));
        return rc;
    }

#if 0
    FIXME - streamOwnerShould expose the function
    rc = clLogStreamOwnerFilterGetClientAsync(hStreamOwnerIdl, pStreamName,
            streamScope, pStreamNodeName,
            &filter, clLogSvrSOFGResponse,
            (void *) hStreamOwnerNode);
#endif
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clLogStreamOwnerFilterGetClientAsync(): rc[0x %x]\n",
                            rc));
    }
    CL_LOG_CLEANUP(clIdlHandleFinalize(hStreamOwnerIdl), CL_OK);

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
ClRcT
clLogFileHdlrFileLocationVerify(ClCharT  *fileLocation)
{
    ClRcT                 rc                          = CL_OK;
    ClIocAddressT         address                     = {{0}};
    ClStatusT              status                      = 0;
    ClIocLogicalAddressT  logLogicalAddr              = 0;
    ClCharT               nodeStr[CL_MAX_NAME_LENGTH] = {0};
    ClBoolT               isLogical                   = CL_FALSE;

    CL_LOG_DEBUG_TRACE(("Enter"));

    sscanf(fileLocation, "%[^:]", nodeStr);

    rc = clLogAddressForLocationGet(nodeStr, &address, &isLogical);
    if( CL_OK != rc )
    {
        return rc;
    }
    if( CL_TRUE == isLogical )
    {
        logLogicalAddr = CL_IOC_LOG_LOGICAL_ADDRESS;
        if( logLogicalAddr == address.iocLogicalAddress )
        {
            return CL_OK;
        }
    }
    else
    {
        rc = clCpmNodeStatusGet( address.iocPhyAddress.nodeAddress,
                                       &status); 
        if( status == CL_STATUS_UP )
        {
            return CL_OK;
        }
    }
    CL_LOG_DEBUG_ERROR(("fileLocation doesn't have proper address"));

    CL_LOG_DEBUG_TRACE(("Exit"));
    return CL_LOG_RC(CL_ERR_INVALID_PARAMETER);
}
ClRcT
clLogSOStreamEntryRecreate(ClUint32T  dsId,
                           ClAddrT    pBuffer,
                           ClUint32T  size,
                           ClPtrT     cookie)
{
    ClRcT                  rc              = CL_OK;
    ClBufferHandleT        msg            = CL_HANDLE_INVALID_VALUE;
    ClLogSvrCommonEoDataT  *pCommonEoData = NULL;

    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clLogStreamOwnerEoEntryGet(NULL, &pCommonEoData);
    if( CL_OK != rc )
    {
        return rc;
    }    

    rc = clBufferCreate(&msg);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBufferCreate()"));
        return rc;
    }    
    rc = clBufferNBytesWrite(msg, (ClUint8T *) pBuffer, size);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBufferNBytesWrite(): rc[0x %x]", rc));
        clBufferDelete(&msg);
        return rc;
    }    
    rc = clLogSOStreamEntryUnpackNAdd(pCommonEoData, msg);

    CL_LOG_CLEANUP(clBufferDelete(&msg), CL_OK);

    if(CL_GET_ERROR_CODE(rc) == CL_ERR_DUPLICATE)
        rc = CL_OK;

    CL_LOG_DEBUG_TRACE(("Exit: rc[0x %x]", rc));
    return rc;
}
void 
clLogStreamOwnerAttributesPrint(ClLogStreamAttrIDLT  *pStreamAttr,
                                ClDebugPrintHandleT  *msg)
{
    CL_LOG_DEBUG_TRACE(("Enter"));

    clDebugPrint(*msg, "fileName       : %s\n", pStreamAttr->fileName.pValue);
    clDebugPrint(*msg, "fileNameLength : %d\n", pStreamAttr->fileName.length);
    clDebugPrint(*msg, "fileLocation   : %s\n", pStreamAttr->fileLocation.pValue);
    clDebugPrint(*msg, "fileLocationLen: %d\n", pStreamAttr->fileName.length);
    clDebugPrint(*msg, "FileUnitSize   : %d\n", pStreamAttr->fileUnitSize);
    clDebugPrint(*msg, "recordSize     : %d\n", pStreamAttr->recordSize);
    clDebugPrint(*msg, "maxFilesRotated: %d\n", pStreamAttr->maxFilesRotated);
    clDebugPrint(*msg, "fileFullAction : %d\n", pStreamAttr->fileFullAction);
    clDebugPrint(*msg, "haProperty     : %d\n", pStreamAttr->haProperty);
    clDebugPrint(*msg, "waterMark(low) : %lld\n", pStreamAttr->waterMark.lowLimit);
    clDebugPrint(*msg, "waterMark(high): %lld\n", pStreamAttr->waterMark.highLimit);
    
    CL_LOG_DEBUG_TRACE(("Exit"));
    return ;
}
static ClRcT
clLogCkptDsIdGet(ClLogSvrEoDataT  *pSvrEoEntry,
                 ClUint32T        *pDsId)
{
    ClRcT   rc = CL_OK;

    CL_LOG_DEBUG_TRACE(("Enter"));

    pSvrEoEntry->nextDsId++;
    *pDsId = pSvrEoEntry->nextDsId;
    rc = clBitmapBitSet(pSvrEoEntry->hDsIdMap, *pDsId);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBitmapBitSet(): rc[0x %x]", rc));
        pSvrEoEntry->nextDsId--;
        return rc;
    }

    CL_LOG_DEBUG_TRACE(("Exit"));
    return CL_OK;
}
ClRcT
clLogSvrShutdown(void)
{
	CL_LOG_DEBUG_TRACE(("Enter"));	

    CL_LOG_CLEANUP(clLogDebugDeregister(), CL_OK);
    CL_LOG_CLEANUP(clLogEvtFinalize(CL_TRUE), CL_OK);
    CL_LOG_CLEANUP(clLogSvrEoDataFinalize(), CL_OK);
    CL_LOG_CLEANUP(clLogFileOwnerShutdown(), CL_OK);
    CL_LOG_CLEANUP(clLogStreamOwnerGlobalShutdown(), CL_OK);
    CL_LOG_CLEANUP(clLogStreamOwnerLocalShutdown(), CL_OK);
    CL_LOG_CLEANUP(clLogMasterShutdown(), CL_OK);
    CL_LOG_CLEANUP(clLogSvrCommonDataFinalize(), CL_OK);
    CL_LOG_CLEANUP(clLogFileOwnerEoDataFree(), CL_OK);
    CL_LOG_CLEANUP(clLogStreamOwnerEoDataFree(), CL_OK);
    CL_LOG_CLEANUP(clLogSvrEoDataFree(), CL_OK);
    CL_LOG_CLEANUP(clIdlHandleFinalize(shLogDummyIdl), CL_OK);

	CL_LOG_DEBUG_TRACE(("Exit"));	
    return CL_OK;
}
ClRcT
clLogMasterCompTableStateRecover(ClLogMasterEoDataT  *pMasterEoEntry,
                                 ClUint8T            *pBuffer,
                                 ClUint32T           dataSize)
{
    ClRcT            rc       = CL_OK;
    ClBufferHandleT  msg      = CL_HANDLE_INVALID_VALUE;
    ClUint32T versionCode = 0;

    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clBufferCreate(&msg);
    if(CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBufferCreate(): rc[0x %x]", rc));
        return rc;
    }
    rc = clBufferNBytesWrite(msg, pBuffer, dataSize);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBufferNBytesWrite(): rc[0x %x]", rc));
        CL_LOG_CLEANUP(clBufferDelete(&msg), CL_OK);
        return rc;
    }

    rc = clXdrUnmarshallClUint32T(msg, &versionCode);
    if( CL_OK != rc)
    {
        CL_LOG_DEBUG_ERROR(("clXdrUnmarshallClUint32T(): rc[%#x]", rc));
        CL_LOG_CLEANUP(clBufferDelete(&msg), CL_OK);
        return rc;
    }
    switch(versionCode)
    {

    case CL_VERSION_CODE(CL_RELEASE_VERSION, CL_MAJOR_VERSION, CL_MINOR_VERSION):
    {
        rc = compTableStateRecoverBaseVersion(msg);
    }
    break;

    default:
        clLogError("COMP", "TBL-RECOVER", "Version [%d.%d.%d] is not supported",
                   CL_VERSION_RELEASE(versionCode), CL_VERSION_MAJOR(versionCode),
                   CL_VERSION_MINOR(versionCode));
        rc = CL_LOG_RC(CL_ERR_VERSION_MISMATCH);
    }

    clBufferDelete(&msg);

    return rc;
}
/* - clLogClntCompInfoGet
 * - Gets the component name and id
 */
ClRcT
clLogClntCompInfoGet(ClLogCompInfoT  *pCompInfo)
{
    ClRcT  rc = CL_OK;

    CL_LOG_DEBUG_TRACE(("Enter"));

    CL_LOG_PARAM_CHK((NULL == pCompInfo), CL_LOG_RC(CL_ERR_NULL_POINTER));

    rc = clCpmComponentNameGet(0, &pCompInfo->compName);
    if( CL_OK != rc)
    {
        CL_LOG_DEBUG_ERROR(("clCpmComponentNameGet(): rc[0x %x]", rc));
        return rc;
    }

    clEoMyEoIocPortGet(&pCompInfo->compId);

    CL_LOG_DEBUG_TRACE(("Exit: %.*s %u", pCompInfo->compName.length,
                        pCompInfo->compName.value, pCompInfo->compId));
    return rc;
}
ClRcT
clLogSOLocalCkptGet(ClLogSOEoDataT  *pSoEoEntry)
{
    ClRcT             rc           = CL_OK; 
    ClLogSvrCommonEoDataT  *pCommonEoData = NULL;
    ClBoolT                ckptExist      = CL_FALSE;

    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clLogStreamOwnerEoEntryGet(NULL, &pCommonEoData);
    if( CL_OK != rc )
    {
        return rc;
    }    

    rc = clCkptLibraryDoesCkptExist(pCommonEoData->hLibCkpt, 
                                    (SaNameT *) &gSOLocalCkptName, 
                                    &ckptExist);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clCkptLibraryDoesCkptExist(): rc[0x %x]", rc));
        return rc;
    }   
    
    rc = clLogStreamOwnerLocalCkptCreate(pCommonEoData->hLibCkpt);
    
    if(CL_OK != rc)
    {
        return rc;
    }

    if( CL_TRUE == ckptExist )
    {
        rc = clLogSOLocalStateRecover(pCommonEoData->hLibCkpt, pSoEoEntry);
    }    

    CL_LOG_DEBUG_TRACE(("Exit: rc[0x %x]", rc));
    return rc;
}    
ClRcT
clLogFileHdlrStreamAttributesCopy(ClLogStreamAttrIDLT     *pSource,
                                  ClLogStreamAttributesT  *pDest)
{
    ClRcT  rc = CL_OK;

    CL_LOG_DEBUG_TRACE(("Enter"));

    pDest->fileUnitSize    = pSource->fileUnitSize;
    pDest->recordSize      = pSource->recordSize;
    pDest->haProperty      = pSource->haProperty;
    pDest->fileFullAction  = pSource->fileFullAction;
    pDest->maxFilesRotated = pSource->maxFilesRotated;
    pDest->flushFreq       = pSource->flushFreq;
    pDest->flushInterval   = pSource->flushInterval;
    pDest->waterMark       = pSource->waterMark;
    pDest->fileName     
        = clHeapCalloc(pSource->fileName.length, sizeof(ClCharT));
    if( NULL == pDest->fileName )
    {
        CL_LOG_DEBUG_ERROR(("clHeapCalloc()"));
        return CL_LOG_RC(CL_ERR_NO_MEMORY);
    }           
    pDest->fileLocation  
        = clHeapCalloc(pSource->fileLocation.length, sizeof(ClCharT));
    if( NULL == pDest->fileLocation )
    {
        CL_LOG_DEBUG_ERROR(("clHeapCalloc()"));
        clHeapFree(pDest->fileName);
        return CL_LOG_RC(CL_ERR_NO_MEMORY);
    }           
    memcpy(pDest->fileName, pSource->fileName.pValue, pSource->fileName.length);
    memcpy(pDest->fileLocation, pSource->fileLocation.pValue, 
           pSource->fileLocation.length);

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
ClRcT
clLogClntFileHdlrHandleUpdate(ClLogFileHandleT   hFileHdlr,
                              ClUint32T          version, 
                              ClUint64T          startRec)
{
    ClRcT               rc            = CL_OK;
    ClLogClntFileHdlrInfoT  *pData        = NULL;
    ClLogClntEoDataT    *pClntEoEntry = NULL;

    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clLogClntEoEntryGet(&pClntEoEntry);
    if( CL_OK != rc )
    {
        return rc;
    }

    rc = clHandleCheckout(pClntEoEntry->hClntHandleDB, hFileHdlr, 
                          (void **) &pData);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCheckout(): rc[0x %x]", rc));
        return rc;
    }
    
    pData->operatingLvl = version;
    pData->startRead    = startRec;
    
    rc = clHandleCheckin(pClntEoEntry->hClntHandleDB, hFileHdlr);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCheckin(); rc[0x %x]", rc));
        return rc;
    }

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
/*
 * Function - clLogStreamOwnerCheckpoint()
 *  - Based on scope , Checkpoint the data
 */
ClRcT
clLogStreamOwnerCheckpoint(ClLogSOEoDataT     *pSoEoEntry,
                           ClLogStreamScopeT  streamScope,
                           ClCntNodeHandleT   hStreamOwnerNode,
                           ClLogStreamKeyT    *pStreamKey)
{
    ClRcT             rc         = CL_OK;
    ClCntHandleT          hStreamTable      = CL_HANDLE_INVALID_VALUE;
    ClLogStreamOwnerDataT *pStreamOwnerData = NULL;

    CL_LOG_DEBUG_TRACE(("Enter"));

    hStreamTable = (CL_LOG_STREAM_GLOBAL == streamScope)
        ? pSoEoEntry->hGStreamOwnerTable 
        : pSoEoEntry->hLStreamOwnerTable ;
    rc = clCntNodeUserDataGet(hStreamTable, hStreamOwnerNode, 
                              (ClCntDataHandleT *) &pStreamOwnerData);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_TRACE(("clCntNodeFind(): rc[0x %x]", rc));
        return rc;
    }    
    if( CL_LOG_STREAM_GLOBAL == streamScope )
    {
        clLogStreamOwnerGlobalCheckpoint(pSoEoEntry, &pStreamKey->streamName,
                                         &pStreamKey->streamScopeNode, 
                                         pStreamOwnerData);
    }    
    else
    {
        clLogStreamOwnerLocalCheckpoint(pSoEoEntry, &pStreamKey->streamName,
                                        &pStreamKey->streamScopeNode,
                                        pStreamOwnerData);
    }    

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}    
ClRcT
clLogSOTableWalkForPrint(ClCntKeyHandleT   key,
                         ClCntDataHandleT  data,
                         ClCntArgHandleT   arg,
                         ClUint32T         size)
{
    ClRcT                  rc                = CL_OK;
    ClLogStreamOwnerDataT  *pStreamOwnerData = (ClLogStreamOwnerDataT *) data;
    ClLogStreamKeyT        *pStreamKey       = (ClLogStreamKeyT *) key;
    ClDebugPrintHandleT    msg               = *((ClDebugPrintHandleT *) arg);

    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clOsalMutexLock_L(&pStreamOwnerData->nodeLock);
    if( CL_OK != rc )
    {
        return rc;
    }
    clDebugPrint(msg, "StreamKey:\n");
    clDebugPrint(msg, "StreamName    : %s\n", pStreamKey->streamName.value);
    clDebugPrint(msg, "StreamNode    : %s\n", pStreamKey->streamScopeNode.value);
    clDebugPrint(msg, "streamNameLen : %d\n", pStreamKey->streamName.length);
    clDebugPrint(msg, "streamScopeLen: %d\n", pStreamKey->streamScopeNode.length);
    clDebugPrint(msg, "--------------------------------------------------\n");
    clDebugPrint(msg, "StreamOwnerData:\n");
    clDebugPrint(msg, "streamId      : %d\n", pStreamOwnerData->streamId);
    clDebugPrint(msg, "MulticastAddr : %lld\n", pStreamOwnerData->streamMcastAddr);
    clDebugPrint(msg, "nodeStatus    : %d\n", pStreamOwnerData->nodeStatus);
    clDebugPrint(msg, "dataSetId     : %d\n", pStreamOwnerData->dsId);
    clDebugPrint(msg, "isNewStream   : %d\n", pStreamOwnerData->isNewStream);
    clLogStreamOwnerAttributesPrint(&pStreamOwnerData->streamAttr, (void**) arg);
    rc = clCntWalk(pStreamOwnerData->hCompTable, clLogCompTableWalkForPrint,
                   arg, 0);
    CL_LOG_CLEANUP(clOsalMutexUnlock_L(&pStreamOwnerData->nodeLock), CL_OK);

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
ClRcT
clLogMasterGlobalCkptRead(ClLogSvrCommonEoDataT  *pCommonEoEntry, ClBoolT switchover)
{
    ClRcT               rc              = CL_OK;
    ClLogMasterEoDataT  *pMasterEoEntry = NULL;

    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clLogMasterEoEntryGet(&pMasterEoEntry, NULL);
    if( CL_OK != rc )
    {
        return rc;
    }

    rc = clLogMasterStateRecover(pCommonEoEntry, pMasterEoEntry, switchover);
    if( CL_OK != rc )
    {
        return rc;
    }

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
static ClRcT
clLogFileHdlrFileHandleDelete(ClLogFileHandleT  hFileHdlr,
                              ClLogHandleT      *phLog)
{
    ClRcT               rc            = CL_OK;
    ClLogClntFileHdlrInfoT  *pData        = NULL;
    ClLogClntEoDataT    *pClntEoEntry = NULL;

    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clLogClntEoEntryGet(&pClntEoEntry);
    if( CL_OK != rc )
    {
        return rc;
    }

    rc = clHandleCheckout(pClntEoEntry->hClntHandleDB, hFileHdlr,
                          (void **) &pData);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCheckout(): rc[0x %x]", rc));
        return rc;
    }

    *phLog = pData->hLog;
    clLogClntFileKeyDestroy(pData->pFileKey); 

    rc = clHandleCheckin(pClntEoEntry->hClntHandleDB, hFileHdlr);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCheckin(); rc[0x %x]", rc));
    }
    CL_LOG_CLEANUP(clHandleDestroy(pClntEoEntry->hClntHandleDB, hFileHdlr), CL_OK);

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
ClRcT
clLogSvrEoDataFinalize(void)
{
    ClRcT            rc           = CL_OK;
    ClLogSvrEoDataT  *pSvrEoEntry = NULL;

	CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clLogSvrEoEntryGet(&pSvrEoEntry, NULL);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clLogSvrEoEntryGet(): rc[0x%x]", rc));
        return rc;
    }

    rc = clOsalMutexLock_L(&pSvrEoEntry->svrStreamTableLock);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clOsalMutexLock_L(): rc[0x %x]", rc));
        return rc;
    }

    if( CL_HANDLE_INVALID_VALUE != pSvrEoEntry->hSvrStreamTable )
    {
        CL_LOG_CLEANUP(clCntDelete(pSvrEoEntry->hSvrStreamTable), CL_OK);
        pSvrEoEntry->hSvrStreamTable = CL_HANDLE_INVALID_VALUE;
    }
    pSvrEoEntry->logInit = CL_FALSE;
    CL_LOG_CLEANUP(clBitmapDestroy(pSvrEoEntry->hDsIdMap), CL_OK);
    CL_LOG_CLEANUP(clOsalMutexUnlock_L(&pSvrEoEntry->svrStreamTableLock),
            CL_OK);
    CL_LOG_CLEANUP(clOsalMutexDestroy_L(&pSvrEoEntry->svrStreamTableLock),
            CL_OK);

	CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
ClRcT
clLogDsIdMapUnpack(ClBufferHandleT  msg,
                   ClLogSOEoDataT   *pSoEoEntry)
{
    ClRcT                   rc     = CL_OK;
    ClUint32T  count = 0;
    ClUint32T  dsId  = 0;

    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clXdrUnmarshallClUint32T(msg, &pSoEoEntry->dsIdCnt);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clXdrUnmarshallClUint32T(): rc[0x %x]",
                    rc));
        return rc;
    }
    for( count = 2; count < pSoEoEntry->dsIdCnt ; count++)
    {
        rc = clXdrUnmarshallClUint32T(msg, &dsId);
        if( CL_OK != rc )
        {
            CL_LOG_DEBUG_ERROR(("clXdrUnmarshallClUint32T(): rc[0x %x]",
                        rc));
            return rc;
        }
        rc = clBitmapBitSet(pSoEoEntry->hDsIdMap, dsId);
        if( CL_OK != rc )
        {
            CL_LOG_DEBUG_ERROR(("clBitmapBitSet(): rc[0x %x]", rc));
            return rc;
    }
    }

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
static void
clLogStreamOwnerEoDataPrint(ClLogSOEoDataT       *pSoEoEntry,
                            ClDebugPrintHandleT  *msg)
{
    ClUint8T   *pDsIdMap = NULL;  
    ClUint32T  length    = 0;
    ClUint32T  nBytes    = 0;
    ClUint32T  count     = 0;
    
    CL_LOG_DEBUG_TRACE(("Enter"));
    
    clDebugPrint(*msg, "G StreamTable  : %p\n", (void *)
            pSoEoEntry->hGStreamOwnerTable);
    clDebugPrint(*msg, "L StreamTable  : %p\n", (void *)
            pSoEoEntry->hLStreamOwnerTable);
    clDebugPrint(*msg, "G StreamMutex  : %p\n", (void *)
            &pSoEoEntry->gStreamTableLock);
    clDebugPrint(*msg, "L StreamMutex  : %p\n", (void *)
            &pSoEoEntry->lStreamTableLock);
    clDebugPrint(*msg, "G StreamTable  : %#llX\n", 
            pSoEoEntry->hCkpt);
    clDebugPrint(*msg, "Num of dataSets: %d\n", pSoEoEntry->dsIdCnt);
    clDebugPrint(*msg, "DataSet Ids:\n");
    clBitmap2BufferGet(pSoEoEntry->hDsIdMap, &length, &pDsIdMap);
    if( NULL != pDsIdMap )
    {
        nBytes = length / CL_BITS_PER_BYTE;
        nBytes++;
        for( count = 0; count < nBytes; count++)
        {
            clDebugPrint(*msg, "%d |", *(pDsIdMap + count));
        }
    }
    
    CL_LOG_DEBUG_TRACE(("Exit"));
    return ; 
}
ClRcT
clLogStreamHandleDataDisplay(ClCharT  **ppRet)
{
    ClRcT             rc            = CL_OK;
    ClLogClntEoDataT  *pClntEoEntry = NULL;

    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clLogClntEoEntryGet(&pClntEoEntry);
    if( CL_OK != rc )
    {
        return rc;
    }
    
    rc = clHandleWalk(pClntEoEntry->hClntHandleDB, clLogStreamDataDump, (void *)ppRet);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleWalk(): rc[0x %x]", rc));
        return rc;
    }

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
ClRcT
clLogHandlerHandleDataDisplay()
{
    ClRcT             rc            = CL_OK;
    ClLogClntEoDataT  *pClntEoEntry = NULL;

    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clLogClntEoEntryGet(&pClntEoEntry);
    if( CL_OK != rc )
    {
        return rc;
    }

    rc = clHandleWalk(pClntEoEntry->hClntHandleDB, clLogHandlerDataDump, NULL);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleWalk(): rc[0x %x]", rc));
        return rc;
    }

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
static ClRcT
clLogMasterFileKeyUnpack(ClLogFileKeyT    *pFileKey,
                         ClBufferHandleT  hFileEntryBuf)
{
    ClRcT rc = CL_OK;
    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clXdrUnmarshallClStringT(hFileEntryBuf, &(pFileKey->fileLocation));
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clXdrUnmarshallClStringT(): rc[0x%x]", rc));
        return rc;
    }

    rc = clXdrUnmarshallClStringT(hFileEntryBuf, &(pFileKey->fileName));
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clXdrUnmarshallClStringT(): rc[0x%x]", rc));
        return rc;
    }

    CL_LOG_DEBUG_TRACE(("Exit"));
    return CL_OK;
}
ClRcT
clLogClntCompNameChkNCompIdGet(SaNameT    *pCompName,
                               ClUint32T  *pClientId)
{
    ClRcT      rc           = CL_OK;
    ClUint32T  count        = 0;
    ClUint32T  localAddr    = 0;
    ClCharT    *pCompPrefix = NULL;
    ClUint32T  compLen      = 0;

    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clLogCompNamePrefixGet(pCompName, &pCompPrefix);
    if( CL_OK != rc )
    {
        return rc;
    }
    compLen = strlen(pCompPrefix);
    for( count = 0; count < nLogAspComps; count++ )
    {
        if( compLen == strlen(aspCompMap[count].pCompName) )
        {
            if( !(memcmp(pCompPrefix, aspCompMap[count].pCompName, compLen)) )
            {
                localAddr = clIocLocalAddressGet();
                localAddr = localAddr << 16;
                localAddr = localAddr | aspCompMap[count].clntId;
            }
        }
    }
    *pClientId = localAddr;

    clHeapFree(pCompPrefix);
    CL_LOG_DEBUG_TRACE(("Exit: %d", *pClientId));
    return rc;
}
static ClRcT ClLogClntStreamWritRecord(ClLogStreamHeaderT    *pStreamHeader,
                              ClUint8T              *pStreamRecords,
                              ClLogSeverityT     severity,
                              ClUint16T          serviceId,
                              ClUint16T          msgId,
                              ClUint32T          clientId,
                              ClCharT            *pMsgHeader,
                              ClUint8T            *pFmtStr,
                              ...)
{
    ClRcT                 rc              = CL_OK;
    ClUint32T             recordSize = 0;
    ClUint8T              *pBuffer        = NULL;
    va_list               args;

    va_start(args, pFmtStr);

    pBuffer = pStreamRecords + (pStreamHeader->recordSize *
              (pStreamHeader->recordIdx % pStreamHeader->maxRecordCount));
    recordSize = pStreamHeader->recordSize;
    CL_ASSERT(recordSize < 4*1024);  // Sanity check the log record size

    pBuffer[recordSize - 1] = CL_LOG_RECORD_WRITE_INPROGRESS; //Mark Record Write In-Progress

    rc = clLogClientMsgWriteWithHeader(severity, pStreamHeader->streamId, serviceId,
                                       msgId, clientId, pStreamHeader->sequenceNum,
                                       pMsgHeader, args,
                                       pStreamHeader->recordSize - 1, pBuffer);
    pBuffer[recordSize - 1] = CL_LOG_RECORD_WRITE_COMPLETE; //Mark Record Write Completed
    if( CL_OK != rc )
    { 
       goto out;
    }
    pStreamHeader->update_status = CL_LOG_STREAM_HEADER_UPDATE_INPROGRESS;
    ++pStreamHeader->sequenceNum;
    ++pStreamHeader->recordIdx;
    pStreamHeader->recordIdx %= (pStreamHeader->maxRecordCount);
    ++pStreamHeader->flushCnt;
    CL_LOG_DEBUG_TRACE(("recordIdx: %u startAck: %u",
                          pStreamHeader->recordIdx, pStreamHeader->startAck));
out:
    va_end(args);
    return rc;
}
ClRcT
clLogInitDataDump(ClHandleDatabaseHandleT  hDb,
                  ClLogHandleT             hLog,
                  ClPtrT                   pCookie)
{
    ClRcT                 rc            = CL_OK;
    ClUint32T             bitmapLen     = 0;
    ClUint32T             i             = 0;
    ClLogClntEoDataT      *pClntEoEntry = NULL;
    ClLogInitHandleDataT  *pData        = NULL;
    ClCharT               ret[MAX_DEBUG_DISPLAY];
    ClCharT               p[MAX_DEBUG_DISPLAY];
    ClCharT               **ppRet       = (ClCharT**) pCookie;
    
    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clLogClntEoEntryGet(&pClntEoEntry);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clLogClntEoEntryGet(): rc[0x %x]", rc));
        return rc;
    }

    rc = clHandleCheckout(pClntEoEntry->hClntHandleDB, hLog, (void **) (&pData));
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCheckout(): rc[0x %x]", rc));
        return rc;
    }

    memset(ret, '\0', MAX_DEBUG_DISPLAY);
    memset(p, '\0', MAX_DEBUG_DISPLAY);
    
    if( CL_LOG_INIT_HANDLE == pData->type )
    {
        snprintf(ret, MAX_DEBUG_DISPLAY, "Init handle: %#llX\nCallbacks: %p\nBitmap:%p\n",
                hLog, (void *) pData->pCallbacks,
                (void *) pData->hStreamBitmap);

        bitmapLen = clBitmapLen(pData->hStreamBitmap);
        if( CL_OK != rc )
        {
            CL_LOG_DEBUG_ERROR(("clBitmapLen(): rc[0x %x]", rc));
            return rc;
        }

        snprintf(p, MAX_DEBUG_DISPLAY, "hStreamBitmap:\n");
        strncat(ret, p, CL_MIN(strlen(p), (MAX_DEBUG_DISPLAY-strlen(ret)-1)));
        
        for( i = 0; i < bitmapLen; i++ )
        {
            if( clBitmapIsBitSet(pData->hStreamBitmap, i, &rc) )
            {
                snprintf(p, MAX_DEBUG_DISPLAY, "%d ", 1);
                strncat(ret, p, CL_MIN(strlen(p), (MAX_DEBUG_DISPLAY-strlen(ret)-1)));
            }
            else
            {
                snprintf(p, MAX_DEBUG_DISPLAY, "%d ", 0);
                strncat(ret, p, CL_MIN(strlen(p), (MAX_DEBUG_DISPLAY-strlen(ret)-1)));
            }
        }

        bitmapLen = clBitmapLen(pData->hFileBitmap);
        if( CL_OK != rc )
        {
            CL_LOG_DEBUG_ERROR(("clBitmapLen(): rc[0x %x]", rc));
            return rc;
        }

        snprintf(p, MAX_DEBUG_DISPLAY, "\nhFileBitmap:\n");
        strncat(ret, p, CL_MIN(strlen(p), (MAX_DEBUG_DISPLAY-strlen(ret)-1)));

        for( i = 0; i < bitmapLen; i++ )
        {
            if( clBitmapIsBitSet(pData->hFileBitmap, i, &rc) )
            {
                snprintf(p, MAX_DEBUG_DISPLAY, "%d ", 1);
                strncat(ret, p, CL_MIN(strlen(p), (MAX_DEBUG_DISPLAY-strlen(ret)-1)));
            }
            else
            {
                snprintf(p, MAX_DEBUG_DISPLAY, "%d ", 0);
                strncat(ret, p, CL_MIN(strlen(p), (MAX_DEBUG_DISPLAY-strlen(ret)-1)));
            }
        }
    }

    rc = clHandleCheckin(pClntEoEntry->hClntHandleDB, hLog);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCheckin(): rc[0x %x]", rc));
        return rc;
    }

    *ppRet = (ClCharT*) clHeapAllocate(strlen(ret) + 1);
    if( NULL == *ppRet )
    {
        CL_LOG_DEBUG_ERROR(("clHeapAllocate(): rc[0x %x]", rc));
        return rc;
    }

    snprintf(*ppRet, strlen(ret)+1, ret);
    
    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
ClRcT
clLogHandlerDataDump(ClHandleDatabaseHandleT hDb, ClStreamHandleT hHandler,
                    void *pCookie)
{
    ClRcT                   rc            = CL_OK;
    ClLogHandlerHandleDataT *pData        = NULL;
    ClLogClntHandlerNodeT   *pHandlerInfo = NULL;
    ClLogClntEoDataT        *pClntEoEntry = NULL;
    ClUint32T               bitmapLen     = 0;
    ClCharT                 s[256];

    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clLogClntEoEntryGet(&pClntEoEntry);
    if( CL_OK != rc )
    {
        return rc;
    }

    rc = clHandleCheckout(hDb, hHandler, (void **) (&pData));
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCheckout(): rc[0x %x]", rc));
        return rc;
    }

    if( CL_LOG_HANDLER_HANDLE == pData->type )
    {
        CL_LOG_DEBUG_TRACE(("Handler handle: %d\nInit handle: %d"
                            " Handler Flag%d\n" , hStream,
                            pData->hLog, pData->handlerFlags));


        rc = clCntNodeUserDataGet(pClntEoEntry->hStreamHandlerTable,
                                  pData->hClntHandlerNode,
                                  (ClCntDataHandleT *) &pHandlerInfo);
        if( CL_OK != rc )
        {
            CL_LOG_DEBUG_ERROR(("clCntNodeUserDataGet(): rc[0x %x]", rc));
            return rc;
        }

        sprintf(s, pHandlerInfo->streamName.length, "%s",
                pHandlerInfo->streamName.value);
        CL_LOG_DEBUG_TRACE(("Stream Name: %s\n", s));

        sprintf(s, pHandlerInfo->nodeName.length, "%s",
                pHandlerInfo->nodeName.value);
        CL_LOG_DEBUG_TRACE(("Node Name: %s\n", s));

        bitmapLen = clBitmapLen(pStreamInfo->hStreamBitmap);
        if( CL_OK != rc )
        {
            CL_LOG_DEBUG_ERROR(("clBitmapLen(): rc[0x %x]", rc));
            return rc;
        }

        CL_LOG_DEBUG_TRACE(("hStreamBitmap:\n"));

        for( i = 0; i < bitmapLen; i++ )
        {
            if( clBitmapIsBitSet(pData->hStreamBitmap, i, &rc) )
            {
                CL_LOG_DEBUG_TRACE(("%d ", 1));
            }
            else
            {
                CL_LOG_DEBUG_TRACE(("%d ", 0));
            }
        }

    }

    rc = clHandleCheckin(hDb, hStream);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCheckin(): rc[0x %x]", rc));
        return rc;
    }

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
ClRcT
clLogStreamDataDump(ClHandleDatabaseHandleT  hDb,
                    ClLogStreamHandleT       hStream,
                    ClPtrT                   pCookie)
{
    ClRcT                   rc            = CL_OK;
    ClLogStreamHandleDataT  *pData        = NULL;
    ClLogClntStreamDataT    *pStreamInfo  = NULL;
    ClLogClntEoDataT        *pClntEoEntry = NULL;
    ClCharT                 **ppRet       = (ClCharT**) pCookie;
    ClCharT                 ret[MAX_DEBUG_DISPLAY];
    ClCharT                 p[MAX_DEBUG_DISPLAY];


    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clLogClntEoEntryGet(&pClntEoEntry);
    if( CL_OK != rc )
    {
        return rc;
    }

    rc = clHandleCheckout(hDb, hStream, (void **) (&pData));
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCheckout(): rc[0x %x]", rc));
        return rc;
    }

    memset(ret, '\0', MAX_DEBUG_DISPLAY);
    memset(p, '\0', MAX_DEBUG_DISPLAY);
    
    if( CL_LOG_STREAM_HANDLE == pData->type )
    {
        snprintf(ret, MAX_DEBUG_DISPLAY, "Stream handle: %#llX\nStreamNode: %p\n",
                hStream, (ClPtrT) pData->hClntStreamNode);

        
        rc = clCntNodeUserDataGet(pClntEoEntry->hClntStreamTable,
                                  pData->hClntStreamNode,
                                  (ClCntDataHandleT *) &pStreamInfo);
        if( CL_OK != rc )
        {
            CL_LOG_DEBUG_ERROR(("clCntNodeUserDataGet(): rc[0x %x]", rc));
            return rc;
        }

        snprintf(p,MAX_DEBUG_DISPLAY, "Stream Header: %p\n",
                (ClCharT *) pStreamInfo->pStreamHeader);
        strncat(ret, p, CL_MIN(strlen(p), (MAX_DEBUG_DISPLAY-strlen(ret)-1)));

        snprintf(p,MAX_DEBUG_DISPLAY, "Shm Name: %.*s", pStreamInfo->shmName.length,
                pStreamInfo->shmName.pValue);
        strncat(ret, p, CL_MIN(strlen(p), (MAX_DEBUG_DISPLAY-strlen(ret)-1)));
        
        rc = clHandleCheckin(hDb, hStream);
        if( CL_OK != rc )
        {
            CL_LOG_DEBUG_ERROR(("clHandleCheckin(): rc[0x %x]", rc));
            return rc;
        }

        *ppRet = (ClCharT*) clHeapAllocate(strlen(ret) + 1);
        if( NULL == *ppRet )
        {
            CL_LOG_DEBUG_ERROR(("clHeapAllocate(): rc[0x %x]", rc));
            return rc;
        }

        snprintf(*ppRet, strlen(ret)+1, ret);
    }

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
ClRcT
clLogClntStreamWriteWithHeader(ClLogClntEoDataT    *pClntEoEntry,
                               ClLogSeverityT      severity,
                               ClUint16T           serviceId,
                               ClUint16T           msgId,
                               const ClCharT             *pMsgHeader,
                               va_list             args,
                               ClCntNodeHandleT    hClntStreamNode)
{
    ClRcT                 rc              = CL_OK;
    ClLogClntStreamDataT  *pClntData      = NULL;
    ClLogStreamHeaderT    *pStreamHeader  = NULL;
    ClUint8T              *pStreamRecords = NULL;
    ClUint32T             nUnAcked        = 0;
    ClUint32T             nDroppedRecords = 0;
    ClUint8T              *pBuffer        = NULL;
    ClUint32T             recordSize = 0;

    CL_LOG_DEBUG_TRACE(("Enter"));
    CL_LOG_DEBUG_VERBOSE(("Severity: %d ServiceId: %hu MsgId: %hu CompId: %u",
                          severity, serviceId, msgId, pClntEoEntry->compId));

    rc = clCntNodeUserDataGet(pClntEoEntry->hClntStreamTable,  hClntStreamNode,
                              (ClCntDataHandleT *) &pClntData);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clCntNodeUserDataGet(): rc[0x %x]", rc));
        return rc;
    }
    pStreamHeader  = pClntData->pStreamHeader;
    pStreamRecords = pClntData->pStreamRecords;
#ifdef NO_SAF
    ClLogStreamKeyT         *pUserKey     = NULL;
    rc = clCntNodeUserKeyGet(pClntEoEntry->hClntStreamTable,
    		                 hClntStreamNode,
                             (ClCntKeyHandleT *) &pUserKey);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clCntNodeUserKeyGet(): rc[0x %x]", rc));
        return rc;
    }
    ClInt32T recSize= pClntData->recSize;
#define __UPDATE_RECORD_SIZE do {                  \
        if(recSize < nbytes )                   \
            recSize = nbytes;                   \
        recSize -= nbytes;                      \
        if(!recSize)                            \
            return CL_OK;                       \
    }while(0)
    ClUint16T streamId = 10;
    ClUint64T sequenceNum = pUserKey->sequenceNum;
    ClUint32T clientId = pClntEoEntry->clientId;
    ClUint8T* pRecord=clHeapAllocate(recSize);
    ClTimeT           timeStamp     = 0;
    ClUint8T          *pRecStart    = pRecord;
    ClUint16T         tmp           = 1;
    ClUint8T          endian        = *(ClUint8T *) &tmp;
    memset(pRecord, 0, recSize);
    if( CL_LOG_MSGID_PRINTF_FMT == msgId )
    {
        ClInt32T nbytes = 0;
        if(recSize < LOG_ASCII_MIN_REC_SIZE ) /* just a minimum record size taking care of the headers*/
        {
            printf("LOG record size has to be minimum [%d] bytes. Got [%d] bytes\n", LOG_ASCII_MIN_REC_SIZE, recSize);
            return CL_LOG_RC(CL_ERR_INVALID_PARAMETER);
        }
        /*
         * In ASCII logging, we dont need header, so just keeping only the
         * required fields
         */
        nbytes = snprintf((ClCharT *)pRecord, recSize, LOG_ASCII_HDR_FMT, endian, severity & 0x1f);
        pRecord += nbytes;
        __UPDATE_RECORD_SIZE;
        {
            ClCharT *pSeverity = (ClCharT *)clLogSeverityStrGet(severity);
            ClCharT c = 0;
            ClInt32T hdrLen = 0;
            ClInt32T len = 0;
            va_list argsCopy;
            ClCharT *pFmtStr ;
            va_copy(argsCopy, args);
            pFmtStr = va_arg(argsCopy, ClCharT *);
            if(pMsgHeader && pMsgHeader[0])
            {
                hdrLen = snprintf(&c, 1, "%s.%05lld : %6s) ",
                                  pMsgHeader, sequenceNum, pSeverity ? pSeverity : "DEBUG");
                if(hdrLen < 0) hdrLen = 0;
            }
            len = vsnprintf(&c, 1, pFmtStr, argsCopy);
            va_end(argsCopy);
            if(len < 0) len = 0;
            hdrLen = CL_MIN(hdrLen, recSize - LOG_ASCII_HDR_LEN - LOG_ASCII_DATA_LEN - 1);
            len = CL_MIN(len, recSize - LOG_ASCII_HDR_LEN - LOG_ASCII_DATA_LEN - hdrLen - 1);
            nbytes = snprintf((ClCharT*)pRecord, recSize - 1, LOG_ASCII_HDR_LEN_FMT, hdrLen);
            pRecord += nbytes;
            __UPDATE_RECORD_SIZE;
            nbytes = snprintf((ClCharT*)pRecord, recSize - 1, LOG_ASCII_DATA_LEN_DELIMITER_FMT, len);
            pRecord += nbytes;
            __UPDATE_RECORD_SIZE;
            if(pMsgHeader && pMsgHeader[0])
            {
                nbytes = snprintf((ClCharT*)pRecord, recSize - 1, "%s.%05lld : %6s) ",
                                  pMsgHeader, sequenceNum, pSeverity ? pSeverity : "DEBUG");
                if(nbytes < 0) nbytes = 0;
                pRecord += nbytes;
                __UPDATE_RECORD_SIZE;
            }
            pFmtStr = va_arg(args, ClCharT *);
            nbytes = vsnprintf((ClCharT*)pRecord, recSize - 1, pFmtStr, args);
            if(nbytes < 0) nbytes = 0;
        }
    }