]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
add --subsystems option to list all available log subsystems
authorJaroslav Kysela <perex@perex.cz>
Wed, 17 Aug 2016 10:10:53 +0000 (12:10 +0200)
committerJaroslav Kysela <perex@perex.cz>
Wed, 17 Aug 2016 10:10:53 +0000 (12:10 +0200)
src/main.c
src/tvhlog.c
src/tvhlog.h

index 261d3034c6450ccba3dfca76f0da7f61fd4f3369..b96e3577ea55183396e0b5cd683329c12c0e6912 100644 (file)
@@ -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 */
index 1b3f83aebc4c386b8ec529920b1f0891919980a6..2160ce288e3de8285bc3064be0dbaddd68dbf834 100644 (file)
@@ -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") },
@@ -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)
index 17eb2a29c442cc332ba30f9bde8bd2a7aafde98c..20e770eb8130131bd01d3028f99c8ba3261b2221 100644 (file)
@@ -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 */