---

Here the minimal set of changes to get logging to syslog done, if you like
the idea I'll expand it a little, currently my plans include

- won't use vsyslog that is BSD only
- write to syslog in a format slightly less ugly
- have a mean to override the ident.

It mixes well with my interactive reporting feature obviously.

 cmdutils.c             | 30 ++++++++++++++++++++++++++++++
 cmdutils.h             |  5 +++++
 cmdutils_common_opts.h |  1 +
 configure              |  2 ++
 4 files changed, 38 insertions(+)

diff --git a/cmdutils.c b/cmdutils.c
index ea86b83..0c8fc5f 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -52,6 +52,9 @@
 #include <sys/time.h>
 #include <sys/resource.h>
 #endif
+#if HAVE_SYSLOG_H
+#include <syslog.h>
+#endif

 struct SwsContext *sws_opts;
 AVDictionary *format_opts, *codec_opts, *resample_opts;
@@ -81,6 +84,24 @@ void log_callback_help(void *ptr, int level, const char 
*fmt, va_list vl)
 {
     vfprintf(stdout, fmt, vl);
 }
+#if HAVE_SYSLOG_H
+static void log_callback_syslog(void *ptr, int level, const char *fmt,
+                                va_list vl)
+{
+    switch (level) {
+    default:
+    case AV_LOG_PANIC:   level = LOG_ALERT;   break;
+    case AV_LOG_FATAL:   level = LOG_CRIT;    break;
+    case AV_LOG_ERROR:   level = LOG_ERR;     break;
+    case AV_LOG_WARNING: level = LOG_WARNING; break;
+    case AV_LOG_INFO:    level = LOG_NOTICE;  break;
+    case AV_LOG_VERBOSE: level = LOG_INFO;    break;
+    case AV_LOG_DEBUG:   level = LOG_DEBUG;   break;
+    }
+
+    vsyslog(level, fmt, vl);
+}
+#endif

 double parse_number_or_die(const char *context, const char *numstr, int type,
                            double min, double max)
@@ -676,6 +697,15 @@ do {                                                       
                    \
     return 0;
 }

+int opt_syslog(void *optctx, const char *opt, const char *arg)
+{
+    if (HAVE_SYSLOG_H && strtol(arg, NULL, 10)) {
+        openlog(program_name, LOG_PID, LOG_USER);
+        av_log_set_callback(log_callback_syslog);
+    }
+    return 0;
+}
+
 int opt_loglevel(void *optctx, const char *opt, const char *arg)
 {
     const struct { const char *name; int level; } log_levels[] = {
diff --git a/cmdutils.h b/cmdutils.h
index 2372b3f..91e9664 100644
--- a/cmdutils.h
+++ b/cmdutils.h
@@ -73,6 +73,11 @@ int opt_default(void *optctx, const char *opt, const char 
*arg);
 int opt_loglevel(void *optctx, const char *opt, const char *arg);

 /**
+ * Output the libav* libraries logging to syslog.
+ */
+int opt_syslog(void *optctx, const char *opt, const char *arg);
+
+/**
  * Limit the execution time.
  */
 int opt_timelimit(void *optctx, const char *opt, const char *arg);
diff --git a/cmdutils_common_opts.h b/cmdutils_common_opts.h
index 619cd89..1c984db 100644
--- a/cmdutils_common_opts.h
+++ b/cmdutils_common_opts.h
@@ -15,3 +15,4 @@
     { "sample_fmts", OPT_EXIT, {.func_arg = show_sample_fmts }, "show 
available audio sample formats" },
     { "loglevel"   , HAS_ARG,  {.func_arg = opt_loglevel},      "set libav* 
logging level", "loglevel" },
     { "v",           HAS_ARG,  {.func_arg = opt_loglevel},      "set libav* 
logging level", "loglevel" },
+    { "syslog",      HAS_ARG,  {.func_arg = opt_syslog},        "output libav* 
logging to the syslog " },
diff --git a/configure b/configure
index 543763f..875c8b4 100755
--- a/configure
+++ b/configure
@@ -1346,6 +1346,7 @@ HAVE_LIST="
     sync_val_compare_and_swap
     sysconf
     sysctl
+    syslog_h
     sys_mman_h
     sys_param_h
     sys_resource_h
@@ -3645,6 +3646,7 @@ check_header dxva2api.h
 check_header io.h
 check_header malloc.h
 check_header poll.h
+check_header syslog.h
 check_header sys/mman.h
 check_header sys/param.h
 check_header sys/resource.h
--
1.8.2.1

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to