Opened 13 years ago
Closed 13 years ago
#1372 closed enhancement (fixed)
New log features: indentation and thread switching indication
Reported by: | bennylp | Owned by: | bennylp |
---|---|---|---|
Priority: | normal | Milestone: | release-2.0-alpha2 |
Component: | common | Version: | trunk |
Keywords: | Cc: | ||
Backport to 1.x milestone: | Backported: |
Description (last modified by bennylp)
Two new features are introduced by this ticket:
1. Indentation
Indentation of log message to give grouping context of the messages. Example:
21:13:35.787 pjsua_call.c Answering call 1: code=200 21:13:35.787 pjsua_media.c ...Call 1: updating media.. 21:13:35.787 pjsua_media.c .....Media session call01:0 is destroyed 21:13:35.787 pjsua_media.c ....Audio channel update.. 21:13:35.787 strm0x22f04d8 .....VAD temporarily disabled 21:13:35.788 strm0x22f04d8 .....Encoder stream started 21:13:35.788 strm0x22f04d8 .....Decoder stream started 21:13:35.788 pjsua_app.c ...Call 1 media 0 [type=audio], status is Active 21:13:35.788 pjsua_media.c ...Conf disconnect: 2 -x- 0 21:13:35.788 pjsua_media.c ...Conf connect: 3 --> 0 21:13:35.788 pjsua_media.c ...Conf connect: 0 --> 3
Use pj_log_push_indent() and pj_log_pop_indent() to use this new feature. The PJ_LOG_HAS_INDENT must be set in the log decoration flag (it is set by default by PJSUA-LIB).
The indentation is applied on per thread basis.
The complete features introduced by this ticket are:
- new functions: pj_log_add_indent(int), pj_log_push_indent(), pj_log_pop_indent()
- new log decor: PJ_LOG_HAS_INDENT
- new macros: PJ_LOG_ENABLE_INDENT (1), PJ_LOG_INDENT_SIZE (1), PJ_LOG_INDENT_CHAR ('.')
Sample code:
#include <pj/log.h> #define THIS_FILE "sample.c" void inner() { PJ_LOG(4,(THIS_FILE, "We're in inner")); } void outer() { PJ_LOG(4,(THIS_FILE, "Calling inner")); pj_log_push_indent(); inner(); pj_log_pop_indent(); } int main() { pj_log_set_decor(pj_log_get_decor() | PJ_LOG_HAS_INDENT); outer(); return 0; }
The sample code above will produce:
21:13:35.787 sample.c Calling inner 21:13:35.787 sample.c .We're in inner
2. Thread Switch Indication
An exclamation mark will be placed before a log message if the caller thread is different than the caller thread of the previous message.
Example:
21:13:35.787 sample.c Thread A is calling the log 21:13:35.787 sample.c ..This one is still from thread A 21:13:35.787 sample.c !Thread B appears (indentation has changed too) 21:13:35.787 sample.c Thread B again 21:13:35.787 sample.c !..Thread A resumes (indentation changed back)
This feature is controlled by the new PJ_LOG_HAS_THREAD_SWC log decor. It is set by default by PJSUA-LIB.
Change History (8)
comment:1 Changed 13 years ago by bennylp
- Description modified (diff)
comment:2 Changed 13 years ago by bennylp
comment:3 Changed 13 years ago by bennylp
comment:4 Changed 13 years ago by bennylp
- Description modified (diff)
comment:5 Changed 13 years ago by bennylp
- Description modified (diff)
comment:6 Changed 13 years ago by bennylp
- Description modified (diff)
comment:7 Changed 13 years ago by bennylp
- Description modified (diff)
comment:8 Changed 13 years ago by bennylp
- Description modified (diff)
- Resolution set to fixed
- Status changed from new to closed
(In [3752]) Implemented re #1372: New log features: indentation and thread switching indication