[vlc-devel] [RFC] logger: add a --syslog-facility option

Pierre Ynard linkfanel at yahoo.fr
Tue May 26 11:59:17 CEST 2009


This is aimed at people using VLC in production environment and wanting
to log their VLC logs separately from the common daemon.log.

This is my first attempt at adding an option and... user interaction,
so:

 - Should we add this option?
 - Should we restrict the log facilities available? (I only put daemon
   and the local ones here)
 - What syntax should we use, is "daemon", "local0" ... fine?


diff --git a/modules/misc/logger.c b/modules/misc/logger.c
index 2cd9a7f..855f481 100644
--- a/modules/misc/logger.c
+++ b/modules/misc/logger.c
@@ -129,6 +129,14 @@ static const char *const mode_list_text[] = { N_("Text"), "HTML"
   "\"text\" (default) and \"html\".")
 #endif
 
+#ifdef HAVE_SYSLOG_H
+static const char *const facility_list[] = { "daemon", "local0", "local1",
+                "local2", "local3", "local4", "local5", "local6", "local7" };
+
+#define SYSLOG_FACILITY_TEXT N_("Syslog facility")
+#define SYSLOG_FACILITY_LONGTEXT N_("Specify the syslog facility")
+#endif
+
 vlc_module_begin ()
     set_shortname( N_( "Logging" ) )
     set_description( N_("File logging") )
@@ -141,6 +149,11 @@ vlc_module_begin ()
     add_string( "logmode", "text", NULL, LOGMODE_TEXT, LOGMODE_LONGTEXT,
                 false )
         change_string_list( mode_list, mode_list_text, 0 )
+#ifdef HAVE_SYSLOG_H
+    add_string( "syslog-facility", "daemon", NULL, SYSLOG_FACILITY_TEXT,
+                SYSLOG_FACILITY_LONGTEXT, true )
+        change_string_list( facility_list, facility_list, 0 )
+#endif
 
     add_obsolete_string( "rrd-file" )
 
@@ -250,7 +263,56 @@ static int Open( vlc_object_t *p_this )
     {
         p_sys->msg.p_file = NULL;
 #ifdef HAVE_SYSLOG_H
-        openlog( "vlc", LOG_PID|LOG_NDELAY, LOG_DAEMON );
+        int i_facility = LOG_DAEMON;
+        char *psz_facility = var_CreateGetString( p_intf, "syslog-facility" );
+        if( psz_facility )
+        {
+            if( !strcmp( psz_facility, "daemon" ) )
+                ;
+            else if( !strcmp( psz_facility, "local0" ) )
+            {
+                i_facility = LOG_LOCAL0;
+            }
+            else if( !strcmp( psz_facility, "local1" ) )
+            {
+                i_facility = LOG_LOCAL1;
+            }
+            else if( !strcmp( psz_facility, "local2" ) )
+            {
+                i_facility = LOG_LOCAL2;
+            }
+            else if( !strcmp( psz_facility, "local3" ) )
+            {
+                i_facility = LOG_LOCAL3;
+            }
+            else if( !strcmp( psz_facility, "local4" ) )
+            {
+                i_facility = LOG_LOCAL4;
+            }
+            else if( !strcmp( psz_facility, "local5" ) )
+            {
+                i_facility = LOG_LOCAL5;
+            }
+            else if( !strcmp( psz_facility, "local6" ) )
+            {
+                i_facility = LOG_LOCAL6;
+            }
+            else if( !strcmp( psz_facility, "local7" ) )
+            {
+                i_facility = LOG_LOCAL7;
+            }
+            else
+            {
+                msg_Warn( p_intf, "invalid syslog facility `%s', using `daemon'", psz_facility );
+            }
+            free( psz_facility );
+        }
+        else
+        {
+            msg_Warn( p_intf, "no syslog facility specified, using `daemon'" );
+        }
+
+        openlog( "vlc", LOG_PID|LOG_NDELAY, i_facility );
 #endif
     }
 
-----

Regards,

-- 
Pierre Ynard
"Une âme dans un corps, c'est comme un dessin sur une feuille de papier."



More information about the vlc-devel mailing list