Changeset 3752 for pjproject/trunk
- Timestamp:
- Sep 18, 2011 2:38:46 PM (13 years ago)
- Location:
- pjproject/trunk/pjlib
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/include/pj/config.h
r3740 r3752 409 409 #endif 410 410 411 /** 412 * Enable log indentation feature. 413 * 414 * Default: 1 415 */ 416 #ifndef PJ_LOG_ENABLE_INDENT 417 # define PJ_LOG_ENABLE_INDENT 1 418 #endif 419 420 /** 421 * Number of PJ_LOG_INDENT_CHAR to put every time pj_log_push_indent() 422 * is called. 423 * 424 * Default: 1 425 */ 426 #ifndef PJ_LOG_INDENT_SIZE 427 # define PJ_LOG_INDENT_SIZE 1 428 #endif 429 430 /** 431 * Log indentation character. 432 * 433 * Default: space 434 */ 435 #ifndef PJ_LOG_INDENT_CHAR 436 # define PJ_LOG_INDENT_CHAR '.' 437 #endif 411 438 412 439 /** -
pjproject/trunk/pjlib/include/pj/log.h
r3553 r3752 82 82 PJ_LOG_HAS_COLOR = 1024, /**< Colorize logs [yes on win32] */ 83 83 PJ_LOG_HAS_LEVEL_TEXT = 2048, /**< Include level text string [no] */ 84 PJ_LOG_HAS_THREAD_ID = 4096 /**< Include thread identification [no] */ 84 PJ_LOG_HAS_THREAD_ID = 4096, /**< Include thread identification [no] */ 85 PJ_LOG_HAS_THREAD_SWC = 8192, /**< Add mark when thread has switched [yes]*/ 86 PJ_LOG_HAS_INDENT =16384 /**< Indentation. Say yes! [yes] */ 85 87 }; 86 88 … … 204 206 PJ_DECL(unsigned) pj_log_get_decor(void); 205 207 208 /** 209 * Add indentation to log message. Indentation will add PJ_LOG_INDENT_CHAR 210 * before the message, and is useful to show the depth of function calls. 211 * 212 * @param indent The indentation to add or substract. Positive value 213 * adds current indent, negative value subtracts current 214 * indent. 215 */ 216 PJ_DECL(void) pj_log_add_indent(int indent); 217 218 /** 219 * Push indentation to the right by default value (PJ_LOG_INDENT). 220 */ 221 PJ_DECL(void) pj_log_push_indent(void); 222 223 /** 224 * Pop indentation (to the left) by default value (PJ_LOG_INDENT). 225 */ 226 PJ_DECL(void) pj_log_pop_indent(void); 206 227 207 228 /** -
pjproject/trunk/pjlib/src/pj/log.c
r3553 r3752 32 32 #endif 33 33 34 static void *g_last_thread; 35 34 36 #if PJ_HAS_THREADS 35 37 static long thread_suspended_tls_id = -1; 38 # if PJ_LOG_ENABLE_INDENT 39 static long thread_indent_tls_id = -1; 40 # endif 41 #endif 42 43 #if !PJ_LOG_ENABLE_INDENT || !PJ_HAS_THREADS 44 static int log_indent; 36 45 #endif 37 46 … … 39 48 static unsigned log_decor = PJ_LOG_HAS_TIME | PJ_LOG_HAS_MICRO_SEC | 40 49 PJ_LOG_HAS_SENDER | PJ_LOG_HAS_NEWLINE | 41 PJ_LOG_HAS_SPACE 50 PJ_LOG_HAS_SPACE | PJ_LOG_HAS_THREAD_SWC | 51 PJ_LOG_HAS_INDENT 42 52 #if defined(PJ_WIN32) && PJ_WIN32!=0 43 53 | PJ_LOG_HAS_COLOR … … 72 82 #endif 73 83 84 #define LOG_MAX_INDENT 80 85 74 86 #if PJ_HAS_THREADS 75 87 static void logging_shutdown(void) … … 79 91 thread_suspended_tls_id = -1; 80 92 } 81 } 82 #endif 93 # if PJ_LOG_ENABLE_INDENT 94 if (thread_indent_tls_id != -1) { 95 pj_thread_local_free(thread_indent_tls_id); 96 thread_indent_tls_id = -1; 97 } 98 # endif 99 } 100 #endif /* PJ_HAS_THREADS */ 101 102 #if PJ_LOG_ENABLE_INDENT && PJ_HAS_THREADS 103 static void log_set_indent(int indent) 104 { 105 if (indent < 0) indent = 0; 106 pj_thread_local_set(thread_indent_tls_id, (void*)(long)indent); 107 } 108 109 static int log_get_raw_indent() 110 { 111 return (long)pj_thread_local_get(thread_indent_tls_id); 112 } 113 114 #else 115 static void log_set_indent(int indent) 116 { 117 log_indent = indent; 118 if (log_indent < 0) log_indent = 0; 119 } 120 121 static int log_get_raw_indent() 122 { 123 return log_indent; 124 } 125 #endif /* PJ_LOG_ENABLE_INDENT && PJ_HAS_THREADS */ 126 127 static int log_get_indent() 128 { 129 int indent = log_get_raw_indent(); 130 return indent > LOG_MAX_INDENT ? LOG_MAX_INDENT : indent; 131 } 132 133 PJ_DEF(void) pj_log_add_indent(int indent) 134 { 135 log_set_indent(log_get_raw_indent() + indent); 136 } 137 138 PJ_DEF(void) pj_log_push_indent(void) 139 { 140 pj_log_add_indent(PJ_LOG_INDENT_SIZE); 141 } 142 143 PJ_DEF(void) pj_log_pop_indent(void) 144 { 145 pj_log_add_indent(-PJ_LOG_INDENT_SIZE); 146 } 83 147 84 148 pj_status_t pj_log_init(void) … … 86 150 #if PJ_HAS_THREADS 87 151 if (thread_suspended_tls_id == -1) { 88 pj_thread_local_alloc(&thread_suspended_tls_id); 152 pj_status_t status; 153 status = pj_thread_local_alloc(&thread_suspended_tls_id); 154 if (status != PJ_SUCCESS) 155 return status; 156 157 # if PJ_LOG_ENABLE_INDENT 158 status = pj_thread_local_alloc(&thread_indent_tls_id); 159 if (status != PJ_SUCCESS) { 160 pj_thread_local_free(thread_suspended_tls_id); 161 thread_suspended_tls_id = -1; 162 return status; 163 } 164 # endif 89 165 pj_atexit(&logging_shutdown); 90 166 } 91 167 #endif 168 g_last_thread = NULL; 92 169 return PJ_SUCCESS; 93 170 } … … 243 320 char log_buffer[PJ_LOG_MAX_SIZE]; 244 321 #endif 245 int saved_level, len, print_len ;322 int saved_level, len, print_len, indent; 246 323 247 324 PJ_CHECK_STACK(); … … 277 354 } 278 355 if (log_decor & PJ_LOG_HAS_YEAR) { 279 *pre++ = ' ';356 if (pre!=log_buffer) *pre++ = ' '; 280 357 pre += pj_utoa(ptime.year, pre); 281 358 } … … 289 366 } 290 367 if (log_decor & PJ_LOG_HAS_TIME) { 291 *pre++ = ' ';368 if (pre!=log_buffer) *pre++ = ' '; 292 369 pre += pj_utoa_pad(ptime.hour, pre, 2, '0'); 293 370 *pre++ = ':'; … … 303 380 enum { SENDER_WIDTH = 14 }; 304 381 int sender_len = strlen(sender); 305 *pre++ = ' ';382 if (pre!=log_buffer) *pre++ = ' '; 306 383 if (sender_len <= SENDER_WIDTH) { 307 384 while (sender_len < SENDER_WIDTH) … … 335 412 *pre++ = ' '; 336 413 337 if (log_decor & PJ_LOG_HAS_SPACE) { 414 if (log_decor & PJ_LOG_HAS_THREAD_SWC) { 415 void *current_thread = (void*)pj_thread_this(); 416 if (current_thread != g_last_thread) { 417 *pre++ = '!'; 418 g_last_thread = current_thread; 419 } else { 420 *pre++ = ' '; 421 } 422 } else if (log_decor & PJ_LOG_HAS_SPACE) { 338 423 *pre++ = ' '; 339 424 } 425 426 #if PJ_LOG_ENABLE_INDENT 427 if (log_decor & PJ_LOG_HAS_INDENT) { 428 indent = log_get_indent(); 429 if (indent > 0) { 430 pj_memset(pre, PJ_LOG_INDENT_CHAR, indent); 431 pre += indent; 432 } 433 } 434 #endif 340 435 341 436 len = pre - log_buffer;
Note: See TracChangeset
for help on using the changeset viewer.