[vlc-commits] libvlc: helper to log to a FILE

Rémi Denis-Courmont git at videolan.org
Wed Apr 18 23:13:41 CEST 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Apr 19 00:13:21 2012 +0300| [d4dd87619e02769e942b596c44c45d928d704059] | committer: Rémi Denis-Courmont

libvlc: helper to log to a FILE

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d4dd87619e02769e942b596c44c45d928d704059
---

 include/vlc/libvlc.h |   13 ++++++++++++-
 lib/log.c            |   19 +++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletions(-)

diff --git a/include/vlc/libvlc.h b/include/vlc/libvlc.h
index 2a005ff..65056b4 100644
--- a/include/vlc/libvlc.h
+++ b/include/vlc/libvlc.h
@@ -56,11 +56,13 @@
 # define LIBVLC_DEPRECATED
 #endif
 
+#include <stdio.h>
+#include <stdarg.h>
+
 # ifdef __cplusplus
 extern "C" {
 # endif
 
-#include <stdarg.h>
 #include <vlc/libvlc_structures.h>
 
 /** \defgroup libvlc_core LibVLC core
@@ -370,6 +372,15 @@ typedef struct libvlc_log_subscriber
 LIBVLC_API void libvlc_log_subscribe( libvlc_log_subscriber_t *sub,
                                       libvlc_log_cb cb, void *data );
 
+
+/**
+ * Registers a logging callback to a file.
+ * @param stream FILE pointer opened for writing
+ *         (the FILE pointer must remain valid until libvlc_log_unsubscribe())
+ */
+LIBVLC_API void libvlc_log_subscribe_file( libvlc_log_subscriber_t *sub,
+                                           FILE *stream );
+
 /**
  * Deregisters a logging callback from LibVLC.
  * This function is thread-safe.
diff --git a/lib/log.c b/lib/log.c
index 83f66d2..0999c56 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -113,6 +113,25 @@ void libvlc_log_unsubscribe( libvlc_log_subscriber_t *sub )
     vlc_rwlock_unlock (&log_lock);
 }
 
+/*** Helpers for logging to files ***/
+static void libvlc_log_file (void *data, int level, const char *fmt,
+                             va_list ap)
+{
+    FILE *stream = data;
+
+    flockfile (stream);
+    vfprintf (stream, fmt, ap);
+    fputc ('\n', stream);
+    funlockfile (stream);
+    (void) level;
+}
+
+void libvlc_log_subscribe_file (libvlc_log_subscriber_t *sub, FILE *stream)
+{
+    libvlc_log_subscribe (sub, libvlc_log_file, stream);
+}
+
+/*** Stubs for the old interface ***/
 unsigned libvlc_get_log_verbosity( const libvlc_instance_t *p_instance )
 {
     (void) p_instance;



More information about the vlc-commits mailing list