From: Jaroslav Kysela Date: Wed, 17 Aug 2016 10:10:53 +0000 (+0200) Subject: add --subsystems option to list all available log subsystems X-Git-Tag: v4.2.1~377 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1b05429ca0298ee15abb93ecc20cf114748aeaff;p=thirdparty%2Ftvheadend.git add --subsystems option to list all available log subsystems --- diff --git a/src/main.c b/src/main.c index 261d3034c..b96e3577e 100644 --- a/src/main.c +++ b/src/main.c @@ -532,6 +532,21 @@ show_usage exit(0); } +/** + * Show subsystems info + */ +static void +show_subsystems(const char *argv0) +{ + int i; + tvhlog_subsys_t *ts = tvhlog_subsystems; + printf("Subsystems:\n\n"); + for (i = 1, ts++; i < LS_LAST; i++, ts++) { + printf(" %-15s %s\n", ts->name, _(ts->desc)); + } + exit(0); +} + /** * */ @@ -773,7 +788,8 @@ main(int argc, char **argv) opt_dbus = 0, opt_dbus_session = 0, opt_nobackup = 0, - opt_nobat = 0; + opt_nobat = 0, + opt_subsystems = 0; const char *opt_config = NULL, *opt_user = NULL, *opt_group = NULL, @@ -857,6 +873,7 @@ main(int argc, char **argv) #if ENABLE_TRACE { 0, "trace", N_("Enable trace subsystems"), OPT_STR, &opt_log_trace }, #endif + { 0, "subsystems",N_("List subsystems"), OPT_BOOL, &opt_subsystems }, { 0, "fileline", N_("Add file and line numbers to debug"), OPT_BOOL, &opt_fileline }, { 0, "threadid", N_("Add the thread ID to debug"), OPT_BOOL, &opt_threadid }, #if ENABLE_LIBAV @@ -929,6 +946,8 @@ main(int argc, char **argv) show_usage(argv[0], cmdline_opts, ARRAY_SIZE(cmdline_opts), NULL); if (opt_version) show_version(argv[0]); + if (opt_subsystems) + show_subsystems(argv[0]); } /* Additional cmdline processing */ diff --git a/src/tvhlog.c b/src/tvhlog.c index 1b3f83aeb..2160ce288 100644 --- a/src/tvhlog.c +++ b/src/tvhlog.c @@ -67,12 +67,7 @@ static const char *logtxtmeta[9][2] = { {"TRACE", "\033[32m"}, }; -struct logsubsystxt { - const char *name; - const char *desc; -}; - -static struct logsubsystxt logsubsys[] = { +tvhlog_subsys_t tvhlog_subsystems[] = { [LS_NONE] = { "", N_("None") }, [LS_START] = { "START", N_("START") }, [LS_STOP] = { "STOP", N_("STOP") }, @@ -387,11 +382,11 @@ void tvhlogv ( const char *file, int line, int severity, if (severity <= atomic_get(&tvhlog_level)) { if (tvhlog_trace) { ok = htsmsg_get_u32_or_default(tvhlog_trace, "all", 0); - ok = htsmsg_get_u32_or_default(tvhlog_trace, logsubsys[subsys].name, ok); + ok = htsmsg_get_u32_or_default(tvhlog_trace, tvhlog_subsystems[subsys].name, ok); } if (!ok && severity == LOG_DEBUG && tvhlog_debug) { ok = htsmsg_get_u32_or_default(tvhlog_debug, "all", 0); - ok = htsmsg_get_u32_or_default(tvhlog_debug, logsubsys[subsys].name, ok); + ok = htsmsg_get_u32_or_default(tvhlog_debug, tvhlog_subsystems[subsys].name, ok); } } } else { @@ -417,7 +412,7 @@ void tvhlogv ( const char *file, int line, int severity, if (options & TVHLOG_OPT_THREAD) { tvh_strlcatf(buf, sizeof(buf), l, "tid %ld: ", (long)pthread_self()); } - tvh_strlcatf(buf, sizeof(buf), l, "%s: ", logsubsys[subsys].name); + tvh_strlcatf(buf, sizeof(buf), l, "%s: ", tvhlog_subsystems[subsys].name); if (options & TVHLOG_OPT_FILELINE && severity >= LOG_DEBUG) tvh_strlcatf(buf, sizeof(buf), l, "(%s:%d) ", file, line); if (args) diff --git a/src/tvhlog.h b/src/tvhlog.h index 17eb2a29c..20e770eb8 100644 --- a/src/tvhlog.h +++ b/src/tvhlog.h @@ -38,6 +38,11 @@ typedef struct { size_t count; } tvhlog_limit_t; +typedef struct { + const char *name; + const char *desc; +} tvhlog_subsys_t; + /* Config */ extern int tvhlog_level; extern htsmsg_t *tvhlog_debug; @@ -45,6 +50,7 @@ extern htsmsg_t *tvhlog_trace; extern char *tvhlog_path; extern int tvhlog_options; extern pthread_mutex_t tvhlog_mutex; +extern tvhlog_subsys_t tvhlog_subsystems[]; /* Initialise */ void tvhlog_init ( int level, int options, const char *path ); @@ -181,7 +187,8 @@ enum { LS_WEBUI, LS_TIMESHIFT, LS_SCANFILE, - LS_TSFILE + LS_TSFILE, + LS_LAST /* keep this last */ }; /* Macros */