-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dbg: add dbg_printf_id #946
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,7 +130,7 @@ void dbg_handler_set(dbg_print_h *ph, void *arg) | |
|
||
|
||
/* NOTE: This function should not allocate memory */ | ||
static void dbg_vprintf(int level, const char *fmt, va_list ap) | ||
static void dbg_vprintf(struct pl *id, int level, const char *fmt, va_list ap) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a custom log handler should able to call |
||
{ | ||
dbg_lock(); | ||
|
||
|
@@ -171,6 +171,9 @@ static void dbg_vprintf(int level, const char *fmt, va_list ap) | |
(void)re_fprintf(stderr, "[%09llu] ", ticks - dbg.tick); | ||
} | ||
|
||
if (pl_isset(id)) | ||
(void)re_fprintf(stderr, "{%r} ", id); | ||
|
||
(void)re_vfprintf(stderr, fmt, ap); | ||
|
||
if (dbg.flags & DBG_ANSI && level < DBG_DEBUG) | ||
|
@@ -181,7 +184,8 @@ static void dbg_vprintf(int level, const char *fmt, va_list ap) | |
|
||
|
||
/* Formatted output to print handler and/or logfile */ | ||
static void dbg_fmt_vprintf(int level, const char *fmt, va_list ap) | ||
static void dbg_fmt_vprintf(struct pl *id, int level, const char *fmt, | ||
va_list ap) | ||
{ | ||
char buf[256]; | ||
int len; | ||
|
@@ -201,7 +205,7 @@ static void dbg_fmt_vprintf(int level, const char *fmt, va_list ap) | |
|
||
/* Print handler? */ | ||
if (dbg.ph) { | ||
dbg.ph(level, buf, len, dbg.arg); | ||
dbg.ph(id, level, buf, len, dbg.arg); | ||
} | ||
|
||
/* Output to file */ | ||
|
@@ -226,11 +230,31 @@ void dbg_printf(int level, const char *fmt, ...) | |
va_list ap; | ||
|
||
va_start(ap, fmt); | ||
dbg_vprintf(level, fmt, ap); | ||
dbg_vprintf(NULL, level, fmt, ap); | ||
va_end(ap); | ||
|
||
va_start(ap, fmt); | ||
dbg_fmt_vprintf(NULL, level, fmt, ap); | ||
va_end(ap); | ||
} | ||
|
||
|
||
/** | ||
* Print a formatted debug message | ||
* | ||
* @param level Debug level | ||
* @param fmt Formatted string | ||
*/ | ||
void dbg_printf_id(struct pl *id, int level, const char *fmt, ...) | ||
{ | ||
va_list ap; | ||
|
||
va_start(ap, fmt); | ||
dbg_vprintf(id, level, fmt, ap); | ||
va_end(ap); | ||
|
||
va_start(ap, fmt); | ||
dbg_fmt_vprintf(level, fmt, ap); | ||
dbg_fmt_vprintf(id, level, fmt, ap); | ||
va_end(ap); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,10 +53,12 @@ static void usage(void) | |
#endif | ||
|
||
|
||
static void dbg_handler(int level, const char *p, size_t len, void *arg) | ||
static void dbg_handler(struct pl *id, int level, const char *p, size_t len, | ||
void *arg) | ||
{ | ||
(void)level; | ||
(void)arg; | ||
(void)id; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should the id (aka "tag") be part of the log line ? |
||
|
||
printf("%.*s", (int)len, p); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it better to pass "debug_id" via the macro parameters, instead of assume the name ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It follows the same technique used for DEBUG_LEVEL and DEBUG_MODULE.
The compiler errors if
debug_id
is not defined. I think it's much easier for rewriting existing DEBUG code since you have only definedebug_id
and add_ID
. And this needs less reformatting new lines, that was the idea behind it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we consider uppercase:
DEBUG_ID
?