]> git.sesse.net Git - vlc/blobdiff - modules/misc/logger.c
Revert "nativewindowpriv: use fence_fd"
[vlc] / modules / misc / logger.c
index 7e065ffd14a3efbe958a1ffd0cc1b56144d93ba0..e40dd968d53f9c93425976a187deae725d93a6d5 100644 (file)
 
 #include <stdarg.h>
 #include <assert.h>
+#include <errno.h>
 
 #ifdef __ANDROID__
 # include <android/log.h>
 #endif
 
-#define MODE_TEXT 0
-#define MODE_HTML 1
-#define MODE_SYSLOG 2
-
-#ifdef __APPLE__
-#define LOG_DIR "Library/Logs/"
-#endif
-
 #define LOG_FILE_TEXT "vlc-log.txt"
 #define LOG_FILE_HTML "vlc-log.html"
 
@@ -82,9 +75,9 @@
  *****************************************************************************/
 struct intf_sys_t
 {
-    msg_subscription_t *p_sub;
     FILE *p_file;
     const char *footer;
+    char *ident;
 };
 
 /*****************************************************************************
@@ -93,14 +86,13 @@ struct intf_sys_t
 static int  Open    ( vlc_object_t * );
 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);
+static void TextPrint(void *, int, const vlc_log_t *, const char *, va_list);
+static void HtmlPrint(void *, int, const vlc_log_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 vlc_log_t *, const char *, va_list);
 #endif
 #ifdef __ANDROID__
-static void AndroidPrint(void *, int, const msg_item_t *, const char *, va_list);
+static void AndroidPrint(void *, int, const vlc_log_t *, const char *, va_list);
 #endif
 
 /*****************************************************************************
@@ -127,6 +119,10 @@ static const char *const mode_list_text[] = { N_("Text"), "HTML"
 #define LOGMODE_LONGTEXT N_("Specify the logging format.")
 
 #ifdef HAVE_SYSLOG_H
+#define SYSLOG_IDENT_TEXT N_("Syslog ident")
+#define SYSLOG_IDENT_LONGTEXT N_("Set the ident that VLC would use when " \
+  "logging to syslog.")
+
 #define SYSLOG_FACILITY_TEXT N_("Syslog facility")
 #define SYSLOG_FACILITY_LONGTEXT N_("Select the syslog facility where logs " \
   "will be forwarded.")
@@ -170,11 +166,13 @@ 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-ident", "vlc", SYSLOG_IDENT_TEXT,
+                SYSLOG_IDENT_LONGTEXT, true )
     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 )
@@ -201,7 +199,8 @@ static int Open( vlc_object_t *p_this )
     if( p_sys == NULL )
         return VLC_ENOMEM;
 
-    msg_callback_t cb = TextPrint;
+    p_sys->p_file = NULL;
+    vlc_log_cb cb = TextPrint;
     const char *filename = LOG_FILE_TEXT, *header = TEXT_HEADER;
     p_sys->footer = TEXT_FOOTER;
 
@@ -211,6 +210,7 @@ static int Open( vlc_object_t *p_this )
         if( !strcmp( mode, "html" ) )
         {
             p_sys->footer = HTML_FOOTER;
+            filename = LOG_FILE_HTML;
             header = HTML_HEADER;
             cb = HtmlPrint;
         }
@@ -259,20 +259,34 @@ static int Open( vlc_object_t *p_this )
             i_facility = fac_number[0];
         }
 
-        openlog( "vlc", LOG_PID|LOG_NDELAY, i_facility );
+        char *psz_syslog_ident = var_InheritString( p_intf, "syslog-ident" );
+        if (unlikely(psz_syslog_ident == NULL))
+        {
+            free( p_sys );
+            return VLC_ENOMEM;
+        }
+
+        p_sys->ident = psz_syslog_ident;
+        openlog( p_sys->ident, LOG_PID|LOG_NDELAY, i_facility );
+
         p_sys->p_file = NULL;
     }
     else
 #endif
 #ifdef __ANDROID__
-    if( cb != AndroidPrint )
+    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 )
@@ -289,18 +303,20 @@ static int Open( vlc_object_t *p_this )
         /* Open the log file and remove any buffering for the stream */
         msg_Dbg( p_intf, "opening logfile `%s'", filename );
         p_sys->p_file = vlc_fopen( filename, "at" );
-        free( psz_file );
         if( p_sys->p_file == NULL )
         {
-            msg_Err( p_intf, "error opening logfile `%s': %m", filename );
+            msg_Err( p_intf, "error opening logfile `%s': %s", filename,
+                     vlc_strerror_c(errno) );
+            free( psz_file );
             free( p_sys );
             return VLC_EGENERIC;
         }
+        free( psz_file );
         setvbuf( p_sys->p_file, NULL, _IONBF, 0 );
         fputs( header, p_sys->p_file );
     }
 
-    p_sys->p_sub = vlc_Subscribe( cb, p_intf );
+    vlc_LogSet( p_intf->p_libvlc, cb, p_intf );
     return VLC_SUCCESS;
 }
 
@@ -313,14 +329,18 @@ 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_LogSet( p_intf->p_libvlc, NULL, NULL );
 
     /* Close the log file */
 #ifdef HAVE_SYSLOG_H
     if( p_sys->p_file == NULL )
+    {
         closelog();
+        free( p_sys->ident );
+    }
     else
 #endif
+    if( p_sys->p_file )
     {
         fputs( p_sys->footer, p_sys->p_file );
         fclose( p_sys->p_file );
@@ -359,7 +379,7 @@ static const android_LogPriority prioritytype[4] = {
     ANDROID_LOG_DEBUG
 };
 
-static void AndroidPrint( void *opaque, int type, const msg_item_t *item,
+static void AndroidPrint( void *opaque, int type, const vlc_log_t *item,
                        const char *fmt, va_list ap )
 {
     (void)item;
@@ -369,12 +389,12 @@ static void AndroidPrint( void *opaque, int type, const msg_item_t *item,
         return;
 
     int canc = vlc_savecancel();
-    __android_log_vprint(prioritytype[type], "vlc", fmt, ap);
+    __android_log_vprint(prioritytype[type], "VLC", fmt, ap);
     vlc_restorecancel( canc );
 }
 #endif
 
-static void TextPrint( void *opaque, int type, const msg_item_t *item,
+static void TextPrint( void *opaque, int type, const vlc_log_t *item,
                        const char *fmt, va_list ap )
 {
     intf_thread_t *p_intf = opaque;
@@ -393,7 +413,7 @@ static void TextPrint( void *opaque, int type, const msg_item_t *item,
 }
 
 #ifdef HAVE_SYSLOG_H
-static void SyslogPrint( void *opaque, int type, const msg_item_t *item,
+static void SyslogPrint( void *opaque, int type, const vlc_log_t *item,
                          const char *fmt, va_list ap )
 {
     static const int i_prio[4] = { LOG_INFO, LOG_ERR, LOG_WARNING, LOG_DEBUG };
@@ -418,7 +438,7 @@ static void SyslogPrint( void *opaque, int type, const msg_item_t *item,
 }
 #endif
 
-static void HtmlPrint( void *opaque, int type, const msg_item_t *item,
+static void HtmlPrint( void *opaque, int type, const vlc_log_t *item,
                        const char *fmt, va_list ap )
 {
     static const unsigned color[4] = {
@@ -436,7 +456,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 );