]> git.sesse.net Git - vlc/blobdiff - modules/misc/logger.c
video_output: remove makefile recursion
[vlc] / modules / misc / logger.c
index 4eed615c702644ebff82f299f0e7d067b8d297a9..e40dd968d53f9c93425976a187deae725d93a6d5 100644 (file)
@@ -37,6 +37,7 @@
 
 #include <stdarg.h>
 #include <assert.h>
+#include <errno.h>
 
 #ifdef __ANDROID__
 # include <android/log.h>
@@ -74,9 +75,9 @@
  *****************************************************************************/
 struct intf_sys_t
 {
-    msg_subscription_t sub;
     FILE *p_file;
     const char *footer;
+    char *ident;
 };
 
 /*****************************************************************************
@@ -85,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
 
 /*****************************************************************************
@@ -119,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.")
@@ -162,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 )
@@ -194,7 +200,7 @@ static int Open( vlc_object_t *p_this )
         return VLC_ENOMEM;
 
     p_sys->p_file = NULL;
-    msg_callback_t cb = TextPrint;
+    vlc_log_cb cb = TextPrint;
     const char *filename = LOG_FILE_TEXT, *header = TEXT_HEADER;
     p_sys->footer = TEXT_FOOTER;
 
@@ -204,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;
         }
@@ -252,7 +259,16 @@ 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
@@ -287,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 );
     }
 
-    vlc_Subscribe( &p_sys->sub, cb, p_intf );
+    vlc_LogSet( p_intf->p_libvlc, cb, p_intf );
     return VLC_SUCCESS;
 }
 
@@ -311,12 +329,15 @@ 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->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 )
@@ -358,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;
@@ -373,7 +394,7 @@ static void AndroidPrint( void *opaque, int type, const msg_item_t *item,
 }
 #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;
@@ -392,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 };
@@ -417,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] = {