Changeset 14 in libcf for trunk/src/cf_debug.c


Ignore:
Timestamp:
01/31/13 22:55:37 (11 years ago)
Author:
cheese
Message:

#1 add test code and fix debug and logging error

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/cf_debug.c

    r12 r14  
    4949} S_CF_DEBUG_CTX, CF_DEBUG_CTX;
    5050
    51 void
     51int
    5252CF_Debug_Local_Print (CF_DEBUG_CTX  * ctx,
    5353                      const char    * fmt,
    5454                      va_list       valist)
    5555{
    56     fprintf (GET_CTX_OSTREAM (ctx), "[DEBUG][%s %s(%d)] ",
     56    fprintf (GET_CTX_OSTREAM (ctx), "[DEBUG][%s:%d][%s] ",
    5757                                    ctx->file,
    58                                     ctx->func,
    59                                     ctx->line);
     58                                    ctx->line,
     59                                    ctx->func);
    6060    vfprintf (GET_CTX_OSTREAM (ctx), fmt, valist);
     61
     62    return CF_OK;
    6163}
    6264
     
    129131        return CF_ERROR_DEBUG_SET_OUTPUT_FD;
    130132    }
     133
     134    return CF_OK;
     135}
     136
     137int
     138CF_Debug_UpdateCtx (CF_Debug_Ctx    ctx,
     139                    const char      * file,
     140                    const char      * func,
     141                    const int       line)
     142{
     143    CF_DEBUG_CTX * context = (CF_DEBUG_CTX *) ctx;
     144
     145    CHECK_INVALID_CTX (ctx);
     146
     147    strncpy (context->file, file, strlen (file));
     148    strncpy (context->func, func, strlen (func));
     149    context->line = line;
    131150
    132151    return CF_OK;
     
    154173                   const char           * fmt, ...)
    155174{
    156     int             i, j;
    157     va_list         valist;
    158     FILE            * fp = GET_CTX_OSTREAM (ctx);
    159 
    160     CHECK_INVALID_CTX (ctx);
     175    int     i, j;
     176    va_list valist;
     177    FILE    * fp = NULL;
     178
     179    CHECK_INVALID_CTX (ctx);
     180    fp = GET_CTX_OSTREAM (ctx);
    161181
    162182    va_start (valist, fmt);
     
    210230    context->callstack.caller = push;
    211231
    212     /* set current context */
    213     sprintf (context->file, "%s", file);
    214     sprintf (context->func, "%s", func);
    215     context->line = line;
     232    CF_Debug_UpdateCtx (ctx, file, func, line);
    216233
    217234    return CF_OK;
     
    233250    if (callstack != NULL)
    234251    {
     252        sprintf (callstack->file    , "%s", pop->file);
    235253        sprintf (callstack->function, "%s", pop->func);
    236254        callstack->line = pop->line;
     
    244262    if (pop->caller != NULL)
    245263    {
    246         sprintf (context->file, "%s", pop->caller->file);
    247         sprintf (context->func, "%s", pop->caller->func);
    248         context->line = pop->caller->line;
    249         context->callstack.caller = pop->caller;
    250     }
    251 
     264        CF_Debug_UpdateCtx (ctx,
     265                            pop->caller->file,
     266                            pop->caller->func,
     267                            pop->caller->line);
     268    }
     269
     270    context->callstack.caller = pop->caller;
    252271    free (pop);
    253272
Note: See TracChangeset for help on using the changeset viewer.