Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add --subsystems option to list all available log subsystems
  • Loading branch information
perexg committed Aug 17, 2016
1 parent ad1255d commit 1b05429
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
21 changes: 20 additions & 1 deletion src/main.c
Expand Up @@ -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);
}

/**
*
*/
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 */
Expand Down
13 changes: 4 additions & 9 deletions src/tvhlog.c
Expand Up @@ -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] = { "<none>", N_("None") },
[LS_START] = { "START", N_("START") },
[LS_STOP] = { "STOP", N_("STOP") },
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion src/tvhlog.h
Expand Up @@ -38,13 +38,19 @@ 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;
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 );
Expand Down Expand Up @@ -181,7 +187,8 @@ enum {
LS_WEBUI,
LS_TIMESHIFT,
LS_SCANFILE,
LS_TSFILE
LS_TSFILE,
LS_LAST /* keep this last */
};

/* Macros */
Expand Down

0 comments on commit 1b05429

Please sign in to comment.