Changeset 98 in libcf


Ignore:
Timestamp:
05/28/13 17:35:32 (11 years ago)
Author:
cheese
Message:

#1 add function to set log level

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/cf_log.h

    r66 r98  
    2828#define CF_LOG_BUFFER_NO                0
    2929
     30/**
     31 * 로그 레벨 사용 안함
     32 *
     33 * @see CF_Log_SetLevel
     34 */
     35#define CF_LOG_NO_LEVEL                 -1
     36
    3037#ifdef __cplusplus
    3138extern "C" {
     
    4754
    4855CF_EXPORT int
    49 CF_Log_SetMT            (const int      mapid,
    50                          const CF_BOOL  flag);
    51 
    52 CF_EXPORT int
    5356CF_Log_Write            (const int  mapid,
    5457                         const char * prefix,
     
    5861CF_Log_Flush            (const int mapid);
    5962
     63CF_EXPORT int
     64CF_Log_SetMT            (const int      mapid,
     65                         const CF_BOOL  flag);
     66
     67CF_EXPORT int
     68CF_Log_SetLevel         (const int level);
     69
    6070#ifdef __cplusplus
    6171}
  • trunk/src/cf_log.c

    r93 r98  
    8888    CF_Log_Ctx  * ctxPool;
    8989    int         ctxSize;
     90    int         level;
    9091} S_CF_LOG_ARRAY, CF_LOG_ARRAY;
    9192
     
    448449 * @param ctx   로그 컨텍스트
    449450 *
    450  * @remark 반드시 먼저 초기화 해야하며, 초기화 시에 주어진 번호보다 작은 아이디 넘버를 사용해야 함
     451 * @remark 반드시 먼저 초기화 해야하며, 초기화 시에 주어진 번호보다 작은 아이디 넘버를 사용
    451452 *
    452453 * @see CF_LOG_OPEN, CF_Log_CreateCtx
     
    531532            return CF_ERROR_LOG_INITIALIZE;
    532533        gLogArray.ctxSize = logPool;
     534        gLogArray.level = CF_LOG_NO_LEVEL;
    533535    }
    534536
     
    564566 * @return 성공 시, CF_OK; 실패 시, 오류 코드
    565567 *
    566  * @param mapid 로그의 아이디 넘버
     568 * @param mapid     로그의 아이디 넘버
    567569 * @param path      로그 파일 경로
    568570 * @param memsize   로그 버퍼 크기
     
    603605
    604606/**
     607 * 로그 버퍼의 데이터를 즉시 로그 파일에 쓰기
     608 *
     609 * @return 성공 시, CF_OK; 실패 시, 오류 코드
     610 *
     611 * @param mapid 로그의 아이디 넘버
     612 */
     613int
     614CF_Log_Flush (const int mapid)
     615{
     616    int         result = 0;
     617    CF_Log_Ctx  ctx = NULL;
     618
     619    result = CF_Log_GetMappedCtx (mapid, &ctx);
     620    if (result < 0)
     621        return result;
     622
     623    result = CF_Log_FlushCtx (ctx);
     624
     625    return result;
     626}
     627
     628/**
     629 * 로그 컨텍스트에 멀티쓰레드 모드 설정
     630 *
     631 * @return 성공 시, CF_OK; 실패 시, 오류 코드
     632 *
     633 * @param mapid 로그의 아이디 넘버
     634 * @param flag  설정/해제 bool 플래그
     635 *
     636 * @see CF_BOOL
     637 */
     638int
     639CF_Log_SetMT (const int     mapid,
     640              const CF_BOOL flag)
     641{
     642    int         result = 0;
     643    CF_Log_Ctx  ctx = NULL;
     644
     645    result = CF_Log_GetMappedCtx (mapid, &ctx);
     646    if (result < 0)
     647        return result;
     648
     649    result = (flag) ? CF_Log_SetMultiThread (ctx) :
     650                      CF_Log_UnsetMultiThread (ctx);
     651
     652    return result;
     653}
     654
     655/**
     656 * 현재 설정된 로그 레벨을 가져옴
     657 *
     658 * @return 성공 시, CF_OK; 실패 시, 오류 코드
     659 *
     660 * @param mapid 로그의 아이디 넘버
     661 * @param flag  설정/해제 bool 플래그
     662 */
     663static int
     664CF_Log_GetLevel (void)
     665{
     666    return (gLogArray.level == CF_LOG_NO_LEVEL) ? gLogArray.ctxSize
     667                                                : gLogArray.level;
     668}
     669
     670/**
     671 * 로그 레벨을 설정
     672 * 지정된 로그 레벨 이하의 아이디 넘버만 로그로 기록하도록 설정
     673 *
     674 * @return 성공 시, CF_OK; 실패 시, 오류 코드
     675 *
     676 * @param mapid 로그의 아이디 넘버
     677 * @param flag  설정/해제 bool 플래그
     678 *
     679 * @see CF_LOG_NO_LEVEL
     680 */
     681int
     682CF_Log_SetLevel (const int level)
     683{
     684    gLogArray.level = level;
     685
     686    return CF_OK;
     687}
     688
     689/**
    605690 * 로그 쓰기
    606691 *
     
    621706    va_list     valist;
    622707
     708    result = CF_Log_GetLevel ();
     709    if (result < mapid)
     710        return CF_OK;
     711
    623712    result = CF_Log_GetMappedCtx (mapid, &ctx);
    624713    if (result < 0)
     
    631720    return result;
    632721}
    633 
    634 /**
    635  * 로그 버퍼의 데이터를 즉시 로그 파일에 쓰기
    636  *
    637  * @return 성공 시, CF_OK; 실패 시, 오류 코드
    638  *
    639  * @param mapid 로그의 아이디 넘버
    640  */
    641 int
    642 CF_Log_Flush (const int mapid)
    643 {
    644     int         result = 0;
    645     CF_Log_Ctx  ctx = NULL;
    646 
    647     result = CF_Log_GetMappedCtx (mapid, &ctx);
    648     if (result < 0)
    649         return result;
    650 
    651     result = CF_Log_FlushCtx (ctx);
    652 
    653     return result;
    654 }
    655 
    656 /**
    657  * 로그 컨텍스트에 멀티쓰레드 모드 설정
    658  *
    659  * @return 성공 시, CF_OK; 실패 시, 오류 코드
    660  *
    661  * @param mapid 로그의 아이디 넘버
    662  * @param flag  설정/해제 bool 플래그
    663  *
    664  * @see CF_BOOL
    665  */
    666 int
    667 CF_Log_SetMT (const int     mapid,
    668               const CF_BOOL flag)
    669 {
    670     int         result = 0;
    671     CF_Log_Ctx  ctx = NULL;
    672 
    673     result = CF_Log_GetMappedCtx (mapid, &ctx);
    674     if (result < 0)
    675         return result;
    676 
    677     if (flag)
    678         result = CF_Log_SetMultiThread (ctx);
    679     else
    680         result = CF_Log_UnsetMultiThread (ctx);
    681 
    682     return result;
    683 }
  • trunk/test/log.c

    r66 r98  
    2626    }
    2727
     28    if (CF_Log_SetLevel (5) < 0)
     29        fprintf (stderr, "failed to set log level\n");
     30
    2831    for (i = 0 ; i < 10 ; i++)
    2932    {
  • trunk/test/test.c

    r96 r98  
    119119    }
    120120
     121    if (CF_Log_SetLevel (5) < 0)
     122        fprintf (stderr, "failed to set log level\n");
     123
    121124    for (i = 0 ; i < 10 ; i++)
    122125    {
Note: See TracChangeset for help on using the changeset viewer.