]> git.sesse.net Git - vlc/blobdiff - modules/misc/logger.c
macosx: allow multiple vout windows in video-wallpaper mode
[vlc] / modules / misc / logger.c
index 9cc4ee6ac956e85c41d1793f9bc0b757b1110c8e..ea827ea76ca6d3b43f6fafb7c5c5d5ae36f14932 100644 (file)
 #include <stdarg.h>
 #include <assert.h>
 
-#define MODE_TEXT 0
-#define MODE_HTML 1
-#define MODE_SYSLOG 2
-
-#ifdef __APPLE__
-#define LOG_DIR "Library/Logs/"
+#ifdef __ANDROID__
+# include <android/log.h>
 #endif
 
 #define LOG_FILE_TEXT "vlc-log.txt"
 #define LOG_FILE_HTML "vlc-log.html"
 
-#define TEXT_HEADER "-- logger module started --\n"
+#define TEXT_HEADER "\xEF\xBB\xBF-- logger module started --\n"
 #define TEXT_FOOTER "-- logger module stopped --\n"
 
 #define HTML_HEADER \
@@ -78,7 +74,7 @@
  *****************************************************************************/
 struct intf_sys_t
 {
-    msg_subscription_t *p_sub;
+    msg_subscription_t sub;
     FILE *p_file;
     const char *footer;
 };
@@ -95,6 +91,9 @@ static void HtmlPrint(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
 
 /*****************************************************************************
  * Module descriptor
@@ -103,27 +102,26 @@ 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")
-#ifndef HAVE_SYSLOG_H
-#define LOGMODE_LONGTEXT N_("Specify the log format. Available choices are " \
-  "\"text\" (default) and \"html\".")
-#else
-
-#define LOGMODE_LONGTEXT N_("Specify the log format. Available choices are " \
-  "\"text\" (default), \"html\", and \"syslog\" (special mode to send to " \
-  "syslog instead of file.")
+#define LOGMODE_LONGTEXT N_("Specify the logging format.")
 
+#ifdef HAVE_SYSLOG_H
 #define SYSLOG_FACILITY_TEXT N_("Syslog facility")
 #define SYSLOG_FACILITY_LONGTEXT N_("Select the syslog facility where logs " \
-  "will be forwarded. Available choices are \"user\" (default), \"daemon\", " \
-  "and \"local0\" through \"local7\".")
+  "will be forwarded.")
 
 /* First in list is the default facility used. */
 #define DEFINE_SYSLOG_FACILITY \
@@ -164,11 +162,11 @@ vlc_module_begin ()
              N_("Log filename"), N_("Specify the log filename."), false )
     add_string( "logmode", "text", LOGMODE_TEXT, LOGMODE_LONGTEXT,
                 false )
-        change_string_list( mode_list, mode_list_text, 0 )
+        change_string_list( mode_list, mode_list_text )
 #ifdef HAVE_SYSLOG_H
     add_string( "syslog-facility", fac_name[0], SYSLOG_FACILITY_TEXT,
                 SYSLOG_FACILITY_LONGTEXT, true )
-        change_string_list( fac_name, fac_name, 0 )
+        change_string_list( fac_name, fac_name )
 #endif
     add_integer( "log-verbose", -1, LOGVERBOSE_TEXT, LOGVERBOSE_LONGTEXT,
            false )
@@ -195,6 +193,7 @@ static int Open( vlc_object_t *p_this )
     if( p_sys == NULL )
         return VLC_ENOMEM;
 
+    p_sys->p_file = NULL;
     msg_callback_t cb = TextPrint;
     const char *filename = LOG_FILE_TEXT, *header = TEXT_HEADER;
     p_sys->footer = TEXT_FOOTER;
@@ -211,6 +210,10 @@ static int Open( vlc_object_t *p_this )
 #ifdef HAVE_SYSLOG_H
         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 );
@@ -253,13 +256,21 @@ static int Open( vlc_object_t *p_this )
         p_sys->p_file = NULL;
     }
     else
+#endif
+#ifdef __ANDROID__
+    if( cb == AndroidPrint )
+    {
+        /* nothing to do */
+    }
+    else
 #endif
     {
         char *psz_file = var_InheritString( p_intf, "logfile" );
         if( !psz_file )
         {
 #ifdef __APPLE__
-            char *home = config_GetUserDir(VLC_DOCUMENTS_DIR);
+# define LOG_DIR "Library/Logs"
+            char *home = config_GetUserDir(VLC_HOME_DIR);
             if( home == NULL
              || asprintf( &psz_file, "%s/"LOG_DIR"/%s", home,
                           filename ) == -1 )
@@ -287,7 +298,7 @@ static int Open( vlc_object_t *p_this )
         fputs( header, p_sys->p_file );
     }
 
-    p_sys->p_sub = vlc_Subscribe( cb, p_intf );
+    vlc_Subscribe( &p_sys->sub, cb, p_intf );
     return VLC_SUCCESS;
 }
 
@@ -300,7 +311,7 @@ static void Close( vlc_object_t *p_this )
     intf_sys_t *p_sys = p_intf->p_sys;
 
     /* Flush the queue and unsubscribe from the message queue */
-    vlc_Unsubscribe( p_sys->p_sub );
+    vlc_Unsubscribe( &p_sys->sub );
 
     /* Close the log file */
 #ifdef HAVE_SYSLOG_H
@@ -308,6 +319,7 @@ static void Close( vlc_object_t *p_this )
         closelog();
     else
 #endif
+    if( p_sys->p_file )
     {
         fputs( p_sys->footer, p_sys->p_file );
         fclose( p_sys->p_file );
@@ -338,6 +350,29 @@ static const char ppsz_type[4][9] = {
     " debug",
 };
 
+#ifdef __ANDROID__
+static const android_LogPriority prioritytype[4] = {
+    ANDROID_LOG_INFO,
+    ANDROID_LOG_ERROR,
+    ANDROID_LOG_WARN,
+    ANDROID_LOG_DEBUG
+};
+
+static void AndroidPrint( void *opaque, int type, const msg_item_t *item,
+                       const char *fmt, va_list ap )
+{
+    (void)item;
+    intf_thread_t *p_intf = opaque;
+
+    if( IgnoreMessage( p_intf, type ) )
+        return;
+
+    int canc = vlc_savecancel();
+    __android_log_vprint(prioritytype[type], "VLC", fmt, ap);
+    vlc_restorecancel( canc );
+}
+#endif
+
 static void TextPrint( void *opaque, int type, const msg_item_t *item,
                        const char *fmt, va_list ap )
 {
@@ -349,8 +384,8 @@ static void TextPrint( void *opaque, int type, const msg_item_t *item,
 
     int canc = vlc_savecancel();
     flockfile( stream );
-    utf8_fprintf( stream, "%s%s: ", item->psz_module, ppsz_type[type] );
-    utf8_fprintf( stream, fmt, ap );
+    fprintf( stream, "%s%s: ", item->psz_module, ppsz_type[type] );
+    vfprintf( stream, fmt, ap );
     putc_unlocked( '\n', stream );
     funlockfile( stream );
     vlc_restorecancel( canc );
@@ -400,7 +435,7 @@ static void HtmlPrint( void *opaque, int type, const msg_item_t *item,
     fprintf( stream, "%s%s: <span style=\"color: #%06x\">",
              item->psz_module, ppsz_type[type], color[type] );
     /* FIXME: encode special ASCII characters */
-    fprintf( stream, fmt, ap );
+    vfprintf( stream, fmt, ap );
     fputs( "</span>\n", stream );
     funlockfile( stream );
     vlc_restorecancel( canc );