Changeset 101 in libcf


Ignore:
Timestamp:
05/28/13 23:45:43 (11 years ago)
Author:
cheese
Message:

#1 change interface to set log level

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/cf_log.h

    r98 r101  
    3131 * 로그 레벨 사용 안함
    3232 *
    33  * @see CF_Log_SetLevel
     33 * @see CF_Log_Initialize
    3434 */
    3535#define CF_LOG_NO_LEVEL                 -1
     
    4040
    4141CF_EXPORT int
    42 CF_Log_Initialize       (const int logPool);
     42CF_Log_Initialize       (const int poolSize,
     43                         const int level);
    4344
    4445CF_EXPORT int
     
    6566                         const CF_BOOL  flag);
    6667
    67 CF_EXPORT int
    68 CF_Log_SetLevel         (const int level);
    69 
    7068#ifdef __cplusplus
    7169}
  • trunk/src/cf_log.c

    r100 r101  
    4949    if (gLogArray.ctxPool[__mapid] == NULL) \
    5050        return CF_ERROR_LOG_NOT_MAPPED_ID
     51
     52#define GET_LOG_LEVEL()                     \
     53    ((gLogArray.level == CF_LOG_NO_LEVEL)   \
     54     ? gLogArray.ctxSize                    \
     55     : gLogArray.level)
     56
     57#define CHECK_LOG_LEVEL(__mapid)    \
     58    if (GET_LOG_LEVEL () < mapid)   \
     59        return CF_OK
    5160
    5261#define LOCK_LOG_CTX(__ctx)             CF_Mutex_Lock (&__ctx->mutex)
     
    519528 * @return 성공 시, CF_OK; 실패 시, 오류 코드
    520529 *
    521  * @param logPool 아이디 넘버 최대 값
     530 * @param poolSize  로그 풀 크기로, 로그 아이디 넘버의 최대 값
     531 * @param level     로그 레벨
     532 *
     533 * @see CF_LOG_NO_LEVEL
    522534 */
    523535int
    524 CF_Log_Initialize (const int logPool)
     536CF_Log_Initialize (const int poolSize, const int level)
    525537{
    526538    memset (&gLogArray, 0x00, sizeof (CF_LOG_ARRAY));
    527539
    528     if (logPool > 0)
     540    if (poolSize > 0)
    529541    {
    530542        gLogArray.ctxPool =
    531             (CF_Log_Ctx *) calloc ((size_t) logPool, sizeof (CF_Log_Ctx));
     543            (CF_Log_Ctx *) calloc ((size_t) poolSize, sizeof (CF_Log_Ctx));
    532544        if (gLogArray.ctxPool == NULL)
    533545            return CF_ERROR_LOG_INITIALIZE;
    534         gLogArray.ctxSize = logPool;
    535         gLogArray.level = CF_LOG_NO_LEVEL;
     546        gLogArray.ctxSize = poolSize;
     547        gLogArray.level = level;
    536548    }
    537549
     
    581593    CF_Log_Ctx  ctx = NULL;
    582594
     595    CHECK_LOG_LEVEL (mapid);
     596
    583597    result = CF_Log_CreateCtx (path, memsize, &ctx);
    584598    if (result < 0)
     
    602616CF_Log_Close (const int mapid)
    603617{
     618    CHECK_LOG_LEVEL (mapid);
     619
    604620    return CF_Log_UnmapCtxID (mapid);
    605621}
     
    652668
    653669    return result;
    654 }
    655 
    656 /**
    657  * 현재 설정된 로그 레벨을 가져옴
    658  *
    659  * @return 로그 레벨이 설정된 경우, 로그 풀 크기; 그 외에, 설정된 로그 레벨
    660  */
    661 static int
    662 CF_Log_GetLevel (void)
    663 {
    664     return (gLogArray.level == CF_LOG_NO_LEVEL) ? gLogArray.ctxSize
    665                                                 : gLogArray.level;
    666 }
    667 
    668 /**
    669  * 로그 레벨을 설정
    670  * 지정된 로그 레벨 이하의 아이디 넘버만 로그로 기록하도록 설정
    671  *
    672  * @return 성공 시, CF_OK; 실패 시, 오류 코드
    673  *
    674  * @param level 설정할 로그 레벨
    675  *
    676  * @see CF_LOG_NO_LEVEL
    677  */
    678 int
    679 CF_Log_SetLevel (const int level)
    680 {
    681     gLogArray.level = level;
    682 
    683     return CF_OK;
    684670}
    685671
     
    703689    va_list     valist;
    704690
    705     result = CF_Log_GetLevel ();
    706     if (result < mapid)
    707         return CF_OK;
     691    CHECK_LOG_LEVEL (mapid);
    708692
    709693    result = CF_Log_GetMappedCtx (mapid, &ctx);
  • trunk/test/log.c

    r98 r101  
    1313    char        logname[16] = {0x00,};
    1414
    15     if (CF_Log_Initialize (10) < 0)
     15    if (CF_Log_Initialize (10, 5) < 0)
    1616    {
    1717        fprintf (stderr, "failed to init. log\n");
     
    2525            fprintf (stderr, "failed to open log\n");
    2626    }
    27 
    28     if (CF_Log_SetLevel (5) < 0)
    29         fprintf (stderr, "failed to set log level\n");
    3027
    3128    for (i = 0 ; i < 10 ; i++)
  • trunk/test/test.c

    r98 r101  
    106106
    107107    /* initialize */
    108     if (CF_Log_Initialize (10) < 0)
     108    if (CF_Log_Initialize (10, 5) < 0)
    109109    {
    110110        fprintf (stderr, "failed to init. log\n");
     
    118118            fprintf (stderr, "failed to open log\n");
    119119    }
    120 
    121     if (CF_Log_SetLevel (5) < 0)
    122         fprintf (stderr, "failed to set log level\n");
    123120
    124121    for (i = 0 ; i < 10 ; i++)
Note: See TracChangeset for help on using the changeset viewer.