Exemplo n.º 1
0
/*****************************************************************************
 函 数 名  : Log_BuildId
 功能描述  : 构建打印点类型的打印输出信息
 输入参数  : VOS_UINT32  ulLogId
                         VOS_UINT8  ucParaCnt
                         VOS_INT32 *plPara
                         VOS_CHAR          *pcDst
                         VOS_UINT32 *pulLen
 输出参数  : 无
 返 回 值  : VOS_VOID
 调用函数  :
 被调函数  :

 修改历史      :
  1.日    期   : 2007年4月24日
        作    者   : 李霄 46160
        修改内容   : 新生成函数

*****************************************************************************/
VOS_VOID Log_BuildId(VOS_UINT32  ulLogId, VOS_UINT8   ucParaCnt, VOS_INT32 *plPara,
                        VOS_CHAR   *pcDst,   VOS_UINT32 *pulLen)
{
    VOS_INT32             lTmpLen;
    VOS_INT32             lSpareLen;
    VOS_INT32             lOccupyLen;
    VOS_UINT8             i;

    *pulLen = 0;

    if (ucParaCnt > LOG_MAX_PARA_CNT)
    {
        ucParaCnt = LOG_MAX_PARA_CNT;
    }

    lTmpLen    = VOS_nsprintf( pcDst, LOG_MAX_COLUMN_VAL, "%d, ", ulLogId);
    LOG_AFFIRM (0 <= lTmpLen)

    lOccupyLen = lTmpLen;
    LOG_AFFIRM(LOG_MAX_COLUMN_VAL >= lOccupyLen)
    lSpareLen  = LOG_MAX_COLUMN_VAL - lOccupyLen;

    lTmpLen    = VOS_nsprintf( pcDst + lOccupyLen, (VOS_UINT32)lSpareLen, "%u, ", LOG_GetTick());
    LOG_AFFIRM(0 <= lTmpLen)

    lOccupyLen += lTmpLen;
    LOG_AFFIRM(LOG_MAX_COLUMN_VAL >= lOccupyLen)
    lSpareLen  = LOG_MAX_COLUMN_VAL - lOccupyLen;

    for (i = 0; i < ucParaCnt; i ++)
    {
        lTmpLen = VOS_nsprintf( pcDst + lOccupyLen, (VOS_UINT32)lSpareLen, "%d, ", *plPara);
        LOG_AFFIRM(0 <= lTmpLen)

        lOccupyLen += lTmpLen;
        LOG_AFFIRM(LOG_MAX_COLUMN_VAL >= lOccupyLen)
        lSpareLen  = LOG_MAX_COLUMN_VAL - lOccupyLen;
        plPara++;
    }

    *pulLen = (VOS_UINT32)(LOG_MAX_COLUMN_VAL - lSpareLen);

    return;
}
Exemplo n.º 2
0
/*****************************************************************************
 函 数 名  : Log_BuildId
 功能描述  : 构建打印点类型的打印输出信息
 输入参数  : unsigned long  ulLogId
                         unsigned char  ucParaCnt
                         long *plPara
                         char          *pcDst
                         unsigned long *pulLen
 输出参数  : 无
 返 回 值  : void
 调用函数  :
 被调函数  :

 修改历史      :
  1.日    期   : 2007年4月24日
        作    者   : 李霄 46160
        修改内容   : 新生成函数

*****************************************************************************/
void Log_BuildId(unsigned long  ulLogId, unsigned char  ucParaCnt, long *plPara,
                    char          *pcDst,   unsigned long *pulLen)
{
    long             lTmpLen;
    long             lSpareLen;
    long             lOccupyLen;
    unsigned char    i;

    *pulLen = 0;

    if (ucParaCnt > LOG_MAX_PARA_CNT)
    {
        ucParaCnt = LOG_MAX_PARA_CNT;
    }

    lTmpLen    = LOG_SNPRINTF( pcDst, LOG_MAX_COLUMN_VAL, "%d, ", ulLogId);
    LOG_AFFIRM (0 <= lTmpLen)

    lOccupyLen = lTmpLen;
    LOG_AFFIRM(LOG_MAX_COLUMN_VAL >= lOccupyLen)
    lSpareLen  = LOG_MAX_COLUMN_VAL - lOccupyLen;

    lTmpLen    = LOG_SNPRINTF( pcDst + lOccupyLen, lSpareLen, "%u, ", LOG_GetTick());
    LOG_AFFIRM(0 <= lTmpLen)

    lOccupyLen += lTmpLen;
    LOG_AFFIRM(LOG_MAX_COLUMN_VAL >= lOccupyLen)
    lSpareLen  = LOG_MAX_COLUMN_VAL - lOccupyLen;

    for (i = 0; i < ucParaCnt; i ++)
    {
        lTmpLen = LOG_SNPRINTF( pcDst + lOccupyLen, lSpareLen, "%d, ", *plPara);
        LOG_AFFIRM(0 <= lTmpLen)

        lOccupyLen += lTmpLen;
        LOG_AFFIRM(LOG_MAX_COLUMN_VAL >= lOccupyLen)
        lSpareLen  = LOG_MAX_COLUMN_VAL - lOccupyLen;
        plPara++;
    }

    *pulLen = (unsigned long)(LOG_MAX_COLUMN_VAL - lSpareLen);

    return;
}
Exemplo n.º 3
0
/*****************************************************************************
 函 数 名  : Log_StrNParam
 功能描述  : 字符串类型的打印函数(N 个参数)
 输入参数  : VOS_CHAR             *cFileName
                         VOS_UINT32      ulLineNum
                         LOG_MODULE_ID_EN  enModuleId
                         LOG_SUBMOD_ID_EN   enSubModId
                         LOG_LEVEL_EN      enLevel
                         VOS_CHAR              *pcOriStr
                         VOS_UINT8     ucParaCnt
                         VOS_INT32              *plPara
 输出参数  : 无
 返 回 值  : VOS_VOID
 调用函数  :
 被调函数  :

 修改历史      :
  1.日    期   : 2007年4月24日
        作    者   : 李霄 46160
        修改内容   : 新生成函数

*****************************************************************************/
VOS_INT32 Log_StrNParam(VOS_CHAR *cFileName, VOS_UINT32 ulLineNum,
             LOG_MODULE_ID_EN  enModuleId, LOG_SUBMOD_ID_EN   enSubModId,
             LOG_LEVEL_EN      enLevel,    VOS_CHAR          *pcOriStr,
             VOS_UINT8         ucParaCnt,  VOS_INT32         *plPara)
{
    VOS_UINT32        ulLen;
    VOS_INT32         ret = VOS_ERR;

    /*lint -e813*/
    VOS_CHAR          acLogStr[LOG_MAX_COLUMN_VAL_EX + 1];
    /*lint +e813*/

    if (LOG_TRUE != g_stLogEnt.ulPrintSwitch)
    {
        return ret;
    }

    if (enLevel > Log_GetPrintLevel(enModuleId))
    {
        return ret;
    }

#if(VOS_OS_VER == VOS_WIN32)

    switch ( enLevel )
    {
        case LOG_LEVEL_ERROR :
            vos_printf("\r\nERROR,");
            break;
        case LOG_LEVEL_WARNING :
            vos_printf("\r\nWARNING,");
            break;
        case LOG_LEVEL_NORMAL :
            vos_printf("\r\nNORMAL,");
            break;
        case LOG_LEVEL_INFO :
            vos_printf("\r\nINFO,");
            break;
        default:
            break;
    }
    vos_printf("%s, L: %d, T: %u, %s", (cFileName + Log_GetPathOffset(cFileName)), ulLineNum, LOG_GetTick(), pcOriStr);

    for (ulLen = 0; ulLen < ucParaCnt; ulLen++)
    {
        vos_printf(",%d ", plPara[ulLen]);
    }
#else
    *((VOS_UINT32*)acLogStr) = (VOS_UINT32)enModuleId;
    *(VOS_UINT32*)(acLogStr + sizeof(VOS_UINT32)) = (VOS_UINT32)enLevel;
    /*加上LOG_MODULE_ID_LEN是由于在LOG内容的头部添加了Module ID
      而造成的偏移*/
    Log_BuildStr(cFileName, ulLineNum, enLevel,  pcOriStr,
                 ucParaCnt, plPara,    acLogStr + LOG_MODULE_ID_LEN, &ulLen);
    ret = Log_BufInput(acLogStr, ulLen + LOG_MODULE_ID_LEN);
#endif

    return ret;
}
Exemplo n.º 4
0
/*****************************************************************************
 函 数 名  : Log_BuildStr
 功能描述  : 构建字符串类型的打印输出信息
 输入参数  : VOS_CHAR          *pcFileName
                         VOS_UINT32  ulLineNum
                         LOG_LEVEL_EN   enPrintLev
                         VOS_CHAR          *pcOriStr
                         VOS_UINT8  ucParaCnt
                         VOS_INT32          *plPara
                         VOS_CHAR          *pcDstStr
                         VOS_UINT32 *pulLen
 输出参数  : 无
 返 回 值  : VOS_VOID
 调用函数  :
 被调函数  :

 修改历史      :
  1.日    期   : 2007年4月24日
        作    者   : 李霄 46160
        修改内容   : 新生成函数

*****************************************************************************/
VOS_VOID Log_BuildStr(VOS_CHAR *pcFileName,  VOS_UINT32  ulLineNum,
                      LOG_LEVEL_EN enPrintLev,  VOS_CHAR   *pcOriStr,
                      VOS_UINT8    ucParaCnt,   VOS_INT32  *plPara,
                      VOS_CHAR    *pcDstStr,    VOS_UINT32 *pulLen)
{
    VOS_INT32            lTmpLen;
    VOS_INT32            lStrLen;
    VOS_INT32            lOffset;
    VOS_INT32            lParamLen;
    VOS_INT32            lSpareLen;
    VOS_INT32            lOccupyLen;
    VOS_UINT8            i;

    *pulLen = 0;

    switch ( enPrintLev )
    {
        case LOG_LEVEL_ERROR :
            lTmpLen    = VOS_nsprintf( pcDstStr, LOG_MAX_COLUMN_VAL, "\nERROR,F: ");
            break;
        case LOG_LEVEL_WARNING :
            lTmpLen    = VOS_nsprintf( pcDstStr, LOG_MAX_COLUMN_VAL, "\nWARNING,F: ");
            break;
        case LOG_LEVEL_NORMAL :
            lTmpLen    = VOS_nsprintf( pcDstStr, LOG_MAX_COLUMN_VAL, "\nNORMAL,F: ");
            break;
        case LOG_LEVEL_INFO :
            lTmpLen    = VOS_nsprintf( pcDstStr, LOG_MAX_COLUMN_VAL, "\nINFO,F: ");
            break;
        default:
            lTmpLen    = VOS_nsprintf( pcDstStr, LOG_MAX_COLUMN_VAL, "\nF: ");
            break;
    }

    lOccupyLen = lTmpLen;
    LOG_AFFIRM(LOG_MAX_COLUMN_VAL >= lOccupyLen)

    lSpareLen  = LOG_MAX_COLUMN_VAL - lOccupyLen;
    LOG_AFFIRM(lSpareLen >= LOG_MAX_FILENAME_LEN)

        /* 将路径去除,只保留文件名称 */
    lOffset = Log_GetPathOffset(pcFileName);
    lTmpLen = (VOS_INT32)strlen(pcFileName + lOffset);
    if (lTmpLen < LOG_MAX_FILENAME_LEN)
    {
        memcpy(pcDstStr + lOccupyLen, pcFileName + lOffset, (VOS_UINT32)lTmpLen);
        lOccupyLen += lTmpLen;
    }
    else
    {
        memcpy(pcDstStr + lOccupyLen, pcFileName + lOffset, LOG_MAX_FILENAME_LEN);
        lOccupyLen += LOG_MAX_FILENAME_LEN;
    }

    lSpareLen   = LOG_MAX_COLUMN_VAL - lOccupyLen;

    lTmpLen = VOS_nsprintf( pcDstStr + lOccupyLen, (VOS_UINT32)lSpareLen,
                           ", Line: %u, Tick: %u, ", ulLineNum, LOG_GetTick());

    lOccupyLen += lTmpLen;
    lSpareLen   = LOG_MAX_COLUMN_VAL - lOccupyLen;

        /*=======================*/ /* 计算输出参数需要的长度 */
    lParamLen = ucParaCnt * LOG_MAX_PARA_LEN;
    lStrLen   = lSpareLen - lParamLen;
    LOG_AFFIRM(0 <= lStrLen)

        /*=======================*/ /* 加入字符串信息 */
    lTmpLen = (VOS_INT32)strlen(pcOriStr);
    if (lTmpLen <= lStrLen)
    {
        memcpy(pcDstStr + lOccupyLen, pcOriStr, (VOS_UINT32)lTmpLen);
        lOccupyLen += lTmpLen;
    }
    else
    {
        memcpy(pcDstStr + lOccupyLen, pcOriStr, (VOS_UINT32)lStrLen);
        lOccupyLen += lStrLen;
    }

    if (0 == ucParaCnt)
    {
        if (LOG_MAX_COLUMN_VAL == lOccupyLen)
        {
            *(pcDstStr + (lOccupyLen - 1)) = '\0';
        }
        else
        {
            *(pcDstStr + lOccupyLen) = '\0';
            lOccupyLen = lOccupyLen + 1;
        }

        LOG_AFFIRM(LOG_MAX_COLUMN_VAL >= lOccupyLen)
        *pulLen = (VOS_UINT32)lOccupyLen;
        return;
    }

    *(pcDstStr + lOccupyLen) = ':';
    lOccupyLen = lOccupyLen + 1;
    LOG_AFFIRM(LOG_MAX_COLUMN_VAL > lOccupyLen)

    lSpareLen = LOG_MAX_COLUMN_VAL - lOccupyLen;

        /*=======================*/ /* 加入参数 */
    for (i = 0; i < ucParaCnt; i++)
    {
        lTmpLen = VOS_nsprintf( pcDstStr + lOccupyLen, (VOS_UINT32)lSpareLen, " %d.", *(plPara + i));
        lOccupyLen += lTmpLen;
        LOG_AFFIRM(LOG_MAX_COLUMN_VAL >= lOccupyLen)

        lSpareLen  = LOG_MAX_COLUMN_VAL - lOccupyLen;
    }

    *pulLen = (VOS_UINT32)(LOG_MAX_COLUMN_VAL - lSpareLen);
    return;
}