[vlc-devel] [PATCH] logger module: supports android "logcat"

Rafaël Carré rafael.carre at gmail.com
Wed Aug 31 08:19:20 CEST 2011


---
 configure.ac          |    3 ++
 modules/misc/logger.c |   50 +++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/configure.ac b/configure.ac
index bcd74f4..e92f619 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3259,6 +3259,9 @@ if test "${enable_android_surface}" = "yes"; then
   fi
 fi
 
+if test "${HAVE_ANDROID}" = "1"; then
+    VLC_ADD_LIBS([logger], [-llog])
+fi
 
 dnl
 dnl  iOS vout module
diff --git a/modules/misc/logger.c b/modules/misc/logger.c
index 6500d07..fe2a804 100644
--- a/modules/misc/logger.c
+++ b/modules/misc/logger.c
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * logger.c : file logging plugin for vlc
+ * logger.c : logging plugin for vlc
  *****************************************************************************
  * Copyright (C) 2002-2008 the VideoLAN team
  * $Id$
@@ -38,6 +38,10 @@
 #include <stdarg.h>
 #include <assert.h>
 
+#ifdef __ANDROID__
+#include <android/log.h>
+#endif
+
 #define MODE_TEXT 0
 #define MODE_HTML 1
 #define MODE_SYSLOG 2
@@ -92,8 +96,10 @@ static void Close   ( vlc_object_t * );
 static void TextPrint(void *, int, const msg_item_t *, const char *, va_list);
 static void HtmlPrint(void *, int, const msg_item_t *, const char *, va_list);
 #ifdef HAVE_SYSLOG_H
-static void SyslogPrint(void *, int, const msg_item_t *, const char *,
-                        va_list);
+static void SyslogPrint(void *, int, const msg_item_t *, const char *, va_list);
+#endif
+#ifdef __ANDROID__
+static void AndroidPrint(void *, int, const msg_item_t *, const char *, va_list);
 #endif
 
 /*****************************************************************************
@@ -103,11 +109,17 @@ static const char *const mode_list[] = { "text", "html"
 #ifdef HAVE_SYSLOG_H
 ,"syslog"
 #endif
+#ifdef __ANDROID__
+,"android"
+#endif
 };
 static const char *const mode_list_text[] = { N_("Text"), "HTML"
 #ifdef HAVE_SYSLOG_H
 , "syslog"
 #endif
+#ifdef __ANDROID__
+,"android"
+#endif
 };
 
 #define LOGMODE_TEXT N_("Log format")
@@ -212,11 +224,17 @@ static int Open( vlc_object_t *p_this )
         else if( !strcmp( mode, "syslog" ) )
             cb = SyslogPrint;
 #endif
+#ifdef __ANDROID__
+        else if( !strcmp( mode, "android" ) )
+            cb = AndroidPrint;
+#endif
         else if( strcmp( mode, "text" ) )
             msg_Warn( p_intf, "invalid log mode `%s', using `text'", mode );
         free( mode );
     }
 
+    p_sys->p_file = NULL;
+
 #ifdef HAVE_SYSLOG_H
     if( cb == SyslogPrint )
     {
@@ -250,10 +268,10 @@ static int Open( vlc_object_t *p_this )
         }
 
         openlog( "vlc", LOG_PID|LOG_NDELAY, i_facility );
-        p_sys->p_file = NULL;
     }
     else
 #endif
+    if( cb == TextPrint || cb == HtmlPrint )
     {
         char *psz_file = var_InheritString( p_intf, "logfile" );
         if( !psz_file )
@@ -303,11 +321,13 @@ static void Close( vlc_object_t *p_this )
     vlc_Unsubscribe( p_sys->p_sub );
 
     /* Close the log file */
-#ifdef HAVE_SYSLOG_H
     if( p_sys->p_file == NULL )
+    {
+#ifdef HAVE_SYSLOG_H
         closelog();
-    else
 #endif
+    }
+    else
     {
         fputs( p_sys->footer, p_sys->p_file );
         fclose( p_sys->p_file );
@@ -405,3 +425,21 @@ static void HtmlPrint( void *opaque, int type, const msg_item_t *item,
     funlockfile( stream );
     vlc_restorecancel( canc );
 }
+
+#ifdef __ANDROID__
+static void AndroidPrint( void *opaque, int type, const msg_item_t *item,
+                       const char *fmt, va_list ap )
+{
+    (void)opaque;
+    (void)item;
+
+    static const android_LogPriority prioritytype[4] = {
+        ANDROID_LOG_INFO,
+        ANDROID_LOG_ERROR,
+        ANDROID_LOG_WARN,
+        ANDROID_LOG_DEBUG
+    };
+
+    __android_log_vprint(prioritytype[type % 4], "vlc", fmt, ap);
+}
+#endif
-- 
1.7.5.4



More information about the vlc-devel mailing list