Changeset 2842


Ignore:
Timestamp:
Jul 21, 2009 12:20:17 PM (15 years ago)
Author:
bennylp
Message:

Ticket #921: New logging option/flag to include caller thread ID

Location:
pjproject/trunk/pjlib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/include/pj/log.h

    r2394 r2842  
    8181    PJ_LOG_HAS_SPACE      =  512, /**< Include two spaces before log [yes]    */ 
    8282    PJ_LOG_HAS_COLOR      = 1024, /**< Colorize logs [yes on win32]           */ 
    83     PJ_LOG_HAS_LEVEL_TEXT = 2048  /**< Include level text string [no]         */ 
     83    PJ_LOG_HAS_LEVEL_TEXT = 2048, /**< Include level text string [no]         */ 
     84    PJ_LOG_HAS_THREAD_ID  = 4096  /**< Include thread identification [no]     */ 
    8485}; 
    8586 
  • pjproject/trunk/pjlib/src/pj/log.c

    r2394 r2842  
    3434static unsigned log_decor = PJ_LOG_HAS_TIME | PJ_LOG_HAS_MICRO_SEC | 
    3535                            PJ_LOG_HAS_SENDER | PJ_LOG_HAS_NEWLINE | 
    36                             PJ_LOG_HAS_SPACE  
     36                            PJ_LOG_HAS_SPACE 
    3737#if defined(PJ_WIN32) && PJ_WIN32!=0 
    3838                            | PJ_LOG_HAS_COLOR 
     
    221221        } 
    222222    } 
     223    if (log_decor & PJ_LOG_HAS_THREAD_ID) { 
     224        enum { THREAD_WIDTH = 12 }; 
     225        const char *thread_name = pj_thread_get_name(pj_thread_this()); 
     226        int thread_len = strlen(thread_name); 
     227        *pre++ = ' '; 
     228        if (thread_len <= THREAD_WIDTH) { 
     229            while (thread_len < THREAD_WIDTH) 
     230                *pre++ = ' ', ++thread_len; 
     231            while (*thread_name) 
     232                *pre++ = *thread_name++; 
     233        } else { 
     234            int i; 
     235            for (i=0; i<THREAD_WIDTH; ++i) 
     236                *pre++ = *thread_name++; 
     237        } 
     238    } 
    223239 
    224240    if (log_decor != 0 && log_decor != PJ_LOG_HAS_NEWLINE) 
Note: See TracChangeset for help on using the changeset viewer.