From f88b32e7c12313215b541fc6f1b24ae81da62632 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Tue, 21 Jul 2009 12:20:17 +0000 Subject: 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 --- pjlib/include/pj/log.h | 3 ++- pjlib/src/pj/log.c | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'pjlib') 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