diff --git a/NEWS b/NEWS index 22d69c22744ef17e74260ee00d33aba2888098fa..216dd1477aa5f7f7084d831802e0ee5e7cc678dc 100644 --- a/NEWS +++ b/NEWS @@ -92,6 +92,10 @@ libVLC: * Add libvlc_audio_output_device_get to get the currently selected audio output device identifier (if there is one available) +Logging + * Use --syslog and --syslog-debug command line options to include debug + messages in syslog. With --syslog, errors and warnings will be sent only. + Changes between 2.1.x and 2.2.0: -------------------------------- diff --git a/configure.ac b/configure.ac index 4168682b239d5dd6c2f8d3ede8794766a5f50abe..6431951e8a06815213a3c707723fa5ceef210221 100644 --- a/configure.ac +++ b/configure.ac @@ -770,18 +770,26 @@ AS_IF([test "${SYS}" != "mingw32"], [ ]) AC_SUBST(LIBPTHREAD) +dnl dnl Check for headers +dnl + dnl POSIX -AC_CHECK_HEADERS([arpa/inet.h pthread.h search.h syslog.h sys/shm.h sys/socket.h]) +AC_CHECK_HEADERS([arpa/inet.h pthread.h search.h sys/shm.h sys/socket.h]) AC_CHECK_HEADERS([net/if.h], [], [], [ #include <sys/types.h> #include <sys/socket.h> ]) +AC_CHECK_HEADER([syslog.h], [have_syslog="yes"], [have_syslog="no"]) +AM_CONDITIONAL([HAVE_SYSLOG], [test "$have_syslog" = "yes"]) + dnl BSD AC_CHECK_HEADERS([netinet/udplite.h sys/param.h sys/mount.h]) + dnl GNU/Linux AC_CHECK_HEADERS([getopt.h linux/dccp.h linux/magic.h mntent.h sys/eventfd.h]) + dnl MacOS AC_CHECK_HEADERS([xlocale.h]) diff --git a/modules/logger/Makefile.am b/modules/logger/Makefile.am index 609f3e92995a59daf5cfd0a2e23993aa1f3a4ff8..0cd2a2c30ba59a0e812081d9934396684602a2f0 100644 --- a/modules/logger/Makefile.am +++ b/modules/logger/Makefile.am @@ -1,5 +1,9 @@ loggerdir = $(pluginsdir)/logger libconsole_logger_plugin_la_SOURCES = logger/console.c - logger_LTLIBRARIES = libconsole_logger_plugin.la + +libsyslog_plugin_la_SOURCES = logger/syslog.c +if HAVE_SYSLOG +logger_LTLIBRARIES += libsyslog_plugin.la +endif diff --git a/modules/logger/syslog.c b/modules/logger/syslog.c new file mode 100644 index 0000000000000000000000000000000000000000..d88ecb47990701b911c100ada3d80ab6d5b9e824 --- /dev/null +++ b/modules/logger/syslog.c @@ -0,0 +1,169 @@ +/***************************************************************************** + * syslog.c: POSIX syslog logger plugin + ***************************************************************************** + * Copyright (C) 2002-2008 the VideoLAN team + * Copyright © 2007-2015 Rémi Denis-Courmont + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <vlc_common.h> +#include <vlc_plugin.h> + +#include <stdarg.h> +#include <syslog.h> + +static const int priorities[4] = { + [VLC_MSG_INFO] = LOG_INFO, + [VLC_MSG_ERR] = LOG_ERR, + [VLC_MSG_WARN] = LOG_WARNING, + [VLC_MSG_DBG] = LOG_DEBUG, +}; + +static void Log(void *opaque, int type, const vlc_log_t *meta, + const char *format, va_list ap) +{ + static const char default_msg[] = "message lost"; + char *str; + int priority = priorities[type]; + + int canc = vlc_savecancel(); + + if (vasprintf(&str, format, ap) == -1) + str = (char *)default_msg; + + if (meta->psz_header != NULL) + syslog(priority, "[%s] %s: %s", meta->psz_header, meta->psz_module, + str); + else + syslog(priority, "%s: %s", meta->psz_module, str); + vlc_restorecancel(canc); + + if (str != default_msg) + free(str); + (void) opaque; +} + +/* First in list is the default facility used. */ +#define DEFINE_SYSLOG_FACILITY \ + DEF("user", LOG_USER), \ + DEF("daemon", LOG_DAEMON), \ + DEF("local0", LOG_LOCAL0), \ + DEF("local1", LOG_LOCAL1), \ + DEF("local2", LOG_LOCAL2), \ + DEF("local3", LOG_LOCAL3), \ + DEF("local4", LOG_LOCAL4), \ + DEF("local5", LOG_LOCAL5), \ + DEF("local6", LOG_LOCAL6), \ + DEF("local7", LOG_LOCAL7) + +#define DEF(a,b) a +static const char *const fac_names[] = { DEFINE_SYSLOG_FACILITY }; +#undef DEF +#define DEF(a,b) b +static const int fac_ids[] = { DEFINE_SYSLOG_FACILITY }; +#undef DEF +#undef DEFINE_SYSLOG_FACILITY + +static int var_InheritFacility(vlc_object_t *obj, const char *varname) +{ + char *str = var_InheritString(obj, varname); + if (unlikely(str == NULL)) + return LOG_USER; /* LOG_USEr is the spec default. */ + + for (size_t i = 0; i < sizeof (fac_ids) / sizeof (fac_ids[0]); i++) + { + if (!strcmp(str, fac_names[i])) + { + free(str); + return fac_ids[i]; + } + } + + msg_Warn(obj, "unknown syslog facility \"%s\"", str); + free(str); + return LOG_USER; +} + +static const char default_ident[] = PACKAGE; + +static vlc_log_cb Open(vlc_object_t *obj, void **sysp) +{ + if (!var_InheritBool(obj, "syslog")) + return NULL; + + char *ident = var_InheritString(obj, "syslog-ident"); + if (ident == NULL) + ident = (char *)default_ident; + *sysp = ident; + + /* Open log */ + int facility = var_InheritFacility(obj, "syslog-facility"); + + openlog(ident, LOG_PID | LOG_NDELAY, facility); + + /* Set priority filter */ + int mask = LOG_MASK(LOG_ERR) | LOG_MASK(LOG_WARNING) | LOG_MASK(LOG_INFO); + if (var_InheritBool(obj, "syslog-debug")) + mask |= LOG_MASK(LOG_DEBUG); + + setlogmask(mask); + + return Log; +} + +static void Close(void *opaque) +{ + char *ident = opaque; + + closelog(); + if (ident != default_ident) + free(ident); +} + +#define SYSLOG_TEXT N_("System log (syslog)") +#define SYSLOG_LONGTEXT N_("Emit log messages through the POSIX system log.") + +#define SYSLOG_DEBUG_TEXT N_("Debug messages") +#define SYSLOG_DEBUG_LONGTEXT N_("Include debug messages in system log.") + +#define SYSLOG_IDENT_TEXT N_("Identity") +#define SYSLOG_IDENT_LONGTEXT N_("Process identity in system log.") + +#define SYSLOG_FACILITY_TEXT N_("Facility") +#define SYSLOG_FACILITY_LONGTEXT N_("System logging facility.") + +vlc_module_begin() + set_shortname(N_( "syslog" )) + set_description(N_("System logger (syslog)")) + set_category(CAT_ADVANCED) + set_subcategory(SUBCAT_ADVANCED_MISC) + set_capability("logger", 20) + set_callbacks(Open, Close) + + add_bool("syslog", false, SYSLOG_TEXT, SYSLOG_LONGTEXT, + false) + add_bool("syslog-debug", false, SYSLOG_DEBUG_TEXT, SYSLOG_DEBUG_LONGTEXT, + false) + add_string("syslog-ident", default_ident, SYSLOG_IDENT_TEXT, + SYSLOG_IDENT_LONGTEXT, true) + add_string("syslog-facility", fac_names[0], SYSLOG_FACILITY_TEXT, + SYSLOG_FACILITY_LONGTEXT, true) + change_string_list(fac_names, fac_names) +vlc_module_end() diff --git a/modules/misc/logger.c b/modules/misc/logger.c index e40dd968d53f9c93425976a187deae725d93a6d5..3b01f0ec4710ead968bda0c2354a25c07f5a7422 100644 --- a/modules/misc/logger.c +++ b/modules/misc/logger.c @@ -66,10 +66,6 @@ " </body>\n" \ "</html>\n" -#ifdef HAVE_SYSLOG_H -#include <syslog.h> -#endif - /***************************************************************************** * intf_sys_t: description and status of log interface *****************************************************************************/ @@ -77,7 +73,6 @@ struct intf_sys_t { FILE *p_file; const char *footer; - char *ident; }; /***************************************************************************** @@ -88,9 +83,6 @@ static void Close ( vlc_object_t * ); 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 vlc_log_t *, const char *, va_list); -#endif #ifdef __ANDROID__ static void AndroidPrint(void *, int, const vlc_log_t *, const char *, va_list); #endif @@ -99,17 +91,11 @@ static void AndroidPrint(void *, int, const vlc_log_t *, const char *, va_list); * Module descriptor *****************************************************************************/ 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 @@ -118,39 +104,6 @@ static const char *const mode_list_text[] = { N_("Text"), "HTML" #define LOGMODE_TEXT N_("Log format") #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.") - -/* First in list is the default facility used. */ -#define DEFINE_SYSLOG_FACILITY \ - DEF( "user", LOG_USER ), \ - DEF( "daemon", LOG_DAEMON ), \ - DEF( "local0", LOG_LOCAL0 ), \ - DEF( "local1", LOG_LOCAL1 ), \ - DEF( "local2", LOG_LOCAL2 ), \ - DEF( "local3", LOG_LOCAL3 ), \ - DEF( "local4", LOG_LOCAL4 ), \ - DEF( "local5", LOG_LOCAL5 ), \ - DEF( "local6", LOG_LOCAL6 ), \ - DEF( "local7", LOG_LOCAL7 ) - -#define DEF( a, b ) a -static const char *const fac_name[] = { DEFINE_SYSLOG_FACILITY }; -#undef DEF -#define DEF( a, b ) b -static const int fac_number[] = { DEFINE_SYSLOG_FACILITY }; -#undef DEF -enum { fac_entries = sizeof(fac_name)/sizeof(fac_name[0]) }; -#undef DEFINE_SYSLOG_FACILITY - -#endif - #define LOGVERBOSE_TEXT N_("Verbosity") #define LOGVERBOSE_LONGTEXT N_("Select the verbosity to use for log or -1 to " \ "use the same verbosity given by --verbose.") @@ -167,13 +120,6 @@ vlc_module_begin () add_string( "logmode", "text", LOGMODE_TEXT, LOGMODE_LONGTEXT, false ) 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 ) -#endif add_integer( "log-verbose", -1, LOGVERBOSE_TEXT, LOGVERBOSE_LONGTEXT, false ) @@ -214,10 +160,6 @@ static int Open( vlc_object_t *p_this ) header = HTML_HEADER; cb = HtmlPrint; } -#ifdef HAVE_SYSLOG_H - else if( !strcmp( mode, "syslog" ) ) - cb = SyslogPrint; -#endif #ifdef __ANDROID__ else if( !strcmp( mode, "android" ) ) cb = AndroidPrint; @@ -227,52 +169,6 @@ static int Open( vlc_object_t *p_this ) free( mode ); } -#ifdef HAVE_SYSLOG_H - if( cb == SyslogPrint ) - { - int i_facility; - char *psz_facility = var_InheritString( p_intf, "syslog-facility" ); - if( psz_facility ) - { - bool b_valid = 0; - for( size_t i = 0; i < fac_entries; ++i ) - { - if( !strcmp( psz_facility, fac_name[i] ) ) - { - i_facility = fac_number[i]; - b_valid = 1; - break; - } - } - if( !b_valid ) - { - msg_Warn( p_intf, "invalid syslog facility `%s', using `%s'", - psz_facility, fac_name[0] ); - i_facility = fac_number[0]; - } - free( psz_facility ); - } - else - { - msg_Warn( p_intf, "no syslog facility specified, using `%s'", - fac_name[0] ); - i_facility = fac_number[0]; - } - - 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 ) { @@ -332,14 +228,6 @@ static void Close( vlc_object_t *p_this ) 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 ); @@ -412,32 +300,6 @@ static void TextPrint( void *opaque, int type, const vlc_log_t *item, vlc_restorecancel( canc ); } -#ifdef HAVE_SYSLOG_H -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 }; - - intf_thread_t *p_intf = opaque; - char *str; - int i_priority = i_prio[type]; - - if( IgnoreMessage( p_intf, type ) - || unlikely(vasprintf( &str, fmt, ap ) == -1) ) - return; - - int canc = vlc_savecancel(); - if( item->psz_header != NULL ) - syslog( i_priority, "[%s] %s%s: %s", item->psz_header, - item->psz_module, ppsz_type[type], str ); - else - syslog( i_priority, "%s%s: %s", - item->psz_module, ppsz_type[type], str ); - vlc_restorecancel( canc ); - free( str ); -} -#endif - static void HtmlPrint( void *opaque, int type, const vlc_log_t *item, const char *fmt, va_list ap ) { diff --git a/src/libvlc-module.c b/src/libvlc-module.c index 7c4c73c00c4f2dae0eb222e7b3720f1bdfe2d361..6176f4ff93adb3d35c6f2c599512ae888d82d9cd 100644 --- a/src/libvlc-module.c +++ b/src/libvlc-module.c @@ -1040,10 +1040,6 @@ static const char *const ppsz_prefres[] = { #define FILE_LOG_LONGTEXT N_( \ "Log all VLC messages to a text file." ) -#define SYSLOG_TEXT N_( "Log to syslog" ) -#define SYSLOG_LONGTEXT N_( \ - "Log all VLC messages to syslog (UNIX systems)." ) - #define ONEINSTANCE_TEXT N_("Allow only one running instance") #if defined( _WIN32 ) || defined( __OS2__ ) #define ONEINSTANCE_LONGTEXT N_( \ @@ -2040,10 +2036,6 @@ vlc_module_begin () add_bool( "file-logging", false, FILE_LOG_TEXT, FILE_LOG_LONGTEXT, true ) -#ifdef HAVE_SYSLOG_H - add_bool ( "syslog", false, SYSLOG_TEXT, SYSLOG_LONGTEXT, - true ) -#endif #if defined (_WIN32) || defined (__APPLE__) add_obsolete_string( "language" ) /* since 2.1.0 */ diff --git a/src/libvlc.c b/src/libvlc.c index 44f17f5e680d525d2bc363d74f6a2354efb2c09d..6aa0edb81927cc2905eeee7816e8f0f31e731a9c 100644 --- a/src/libvlc.c +++ b/src/libvlc.c @@ -455,22 +455,6 @@ dbus_out: free( psz_modules ); free( psz_control ); -#ifdef HAVE_SYSLOG_H - if( var_InheritBool( p_libvlc, "syslog" ) ) - { - char *logmode = var_CreateGetNonEmptyString( p_libvlc, "logmode" ); - var_SetString( p_libvlc, "logmode", "syslog" ); - libvlc_InternalAddIntf( p_libvlc, "logger,none" ); - - if( logmode ) - { - var_SetString( p_libvlc, "logmode", logmode ); - free( logmode ); - } - var_Destroy( p_libvlc, "logmode" ); - } - else -#endif if( var_InheritBool( p_libvlc, "file-logging" ) ) libvlc_InternalAddIntf( p_libvlc, "logger,none" );