summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pjlib/include/pj/log.h3
-rw-r--r--pjlib/src/pj/log.c18
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++ = ' ';