tvhlog: add option to display the thread ID in log messages

This commit is contained in:
Adam Sutton 2013-06-08 12:49:54 +01:00
parent 0767a063fb
commit 2222362f66
3 changed files with 11 additions and 1 deletions

View file

@ -418,6 +418,7 @@ main(int argc, char **argv)
opt_abort = 0,
opt_noacl = 0,
opt_fileline = 0,
opt_threadid = 0,
opt_ipv6 = 0,
opt_tsfile_tuner = 0;
const char *opt_config = NULL,
@ -475,6 +476,7 @@ main(int argc, char **argv)
{ 0, "trace", "Enable trace subsystems", OPT_STR, &opt_log_trace },
#endif
{ 0, "fileline", "Add file and line numbers to debug", OPT_BOOL, &opt_fileline },
{ 0, "threadid", "Add the thread ID to debug", OPT_BOOL, &opt_threadid },
{ 0, "uidebug", "Enable webUI debug (non-minified JS)", OPT_BOOL, &opt_uidebug },
{ 'A', "abort", "Immediately abort", OPT_BOOL, &opt_abort },
{ 0, "noacl", "Disable all access control checks",
@ -588,6 +590,8 @@ main(int argc, char **argv)
}
if (opt_fileline)
log_options |= TVHLOG_OPT_FILELINE;
if (opt_threadid)
log_options |= TVHLOG_OPT_THREAD;
if (opt_log_trace) {
log_level = LOG_TRACE;
log_trace = opt_log_trace;

View file

@ -192,7 +192,12 @@ void tvhlogv ( const char *file, int line,
}
/* Basic message */
l = snprintf(buf, sizeof(buf), "%s: ", subsys);
l = 0;
if (options & TVHLOG_OPT_THREAD) {
pthread_t tid = pthread_self();
l += snprintf(buf + l, sizeof(buf) - l, "tid %ld: ", tid);
}
l += snprintf(buf + l, sizeof(buf) - l, "%s: ", subsys);
if (options & TVHLOG_OPT_FILELINE && severity >= LOG_DEBUG)
l += snprintf(buf + l, sizeof(buf) - l, "(%s:%d) ", file, line);
if (args)

View file

@ -60,6 +60,7 @@ void _tvhlog_hexdump ( const char *file, int line,
#define TVHLOG_OPT_MILLIS 0x0100
#define TVHLOG_OPT_DECORATE 0x0200
#define TVHLOG_OPT_FILELINE 0x0400
#define TVHLOG_OPT_THREAD 0x0800
#define TVHLOG_OPT_ALL 0xFFFF
/* Levels */