diff options
author | Benny Prijono <bennylp@teluu.com> | 2009-07-21 12:20:17 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2009-07-21 12:20:17 +0000 |
commit | f88b32e7c12313215b541fc6f1b24ae81da62632 (patch) | |
tree | 88b14cc4c0060d675c3274338db1306e03e019b9 | |
parent | b7d6ba9e3f1343cc42ecee41c28257171d350ebe (diff) |
Ticket #921: New logging option/flag to include caller thread ID
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@2842 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r-- | pjlib/include/pj/log.h | 3 | ||||
-rw-r--r-- | pjlib/src/pj/log.c | 18 |
2 files changed, 19 insertions, 2 deletions
diff --git a/pjlib/include/pj/log.h b/pjlib/include/pj/log.h index 3f001e16..4b2083c2 100644 --- a/pjlib/include/pj/log.h +++ b/pjlib/include/pj/log.h @@ -80,7 +80,8 @@ enum pj_log_decoration PJ_LOG_HAS_CR = 256, /**< Include carriage return [no] */ PJ_LOG_HAS_SPACE = 512, /**< Include two spaces before log [yes] */ PJ_LOG_HAS_COLOR = 1024, /**< Colorize logs [yes on win32] */ - PJ_LOG_HAS_LEVEL_TEXT = 2048 /**< Include level text string [no] */ + PJ_LOG_HAS_LEVEL_TEXT = 2048, /**< Include level text string [no] */ + PJ_LOG_HAS_THREAD_ID = 4096 /**< Include thread identification [no] */ }; /** diff --git a/pjlib/src/pj/log.c b/pjlib/src/pj/log.c index 303d8936..8025b23c 100644 --- a/pjlib/src/pj/log.c +++ b/pjlib/src/pj/log.c @@ -33,7 +33,7 @@ static int pj_log_max_level = PJ_LOG_MAX_LEVEL; static pj_log_func *log_writer = &pj_log_write; static unsigned log_decor = PJ_LOG_HAS_TIME | PJ_LOG_HAS_MICRO_SEC | PJ_LOG_HAS_SENDER | PJ_LOG_HAS_NEWLINE | - PJ_LOG_HAS_SPACE + PJ_LOG_HAS_SPACE #if defined(PJ_WIN32) && PJ_WIN32!=0 | PJ_LOG_HAS_COLOR #endif @@ -220,6 +220,22 @@ PJ_DEF(void) pj_log( const char *sender, int level, *pre++ = *sender++; } } + if (log_decor & PJ_LOG_HAS_THREAD_ID) { + enum { THREAD_WIDTH = 12 }; + const char *thread_name = pj_thread_get_name(pj_thread_this()); + int thread_len = strlen(thread_name); + *pre++ = ' '; + if (thread_len <= THREAD_WIDTH) { + while (thread_len < THREAD_WIDTH) + *pre++ = ' ', ++thread_len; + while (*thread_name) + *pre++ = *thread_name++; + } else { + int i; + for (i=0; i<THREAD_WIDTH; ++i) + *pre++ = *thread_name++; + } + } if (log_decor != 0 && log_decor != PJ_LOG_HAS_NEWLINE) *pre++ = ' '; |