Commit b20e1eda authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

syslog: convert to logger module

parent 49006c59
...@@ -92,6 +92,10 @@ libVLC: ...@@ -92,6 +92,10 @@ libVLC:
* Add libvlc_audio_output_device_get to get the currently selected audio output device * Add libvlc_audio_output_device_get to get the currently selected audio output device
identifier (if there is one available) 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: Changes between 2.1.x and 2.2.0:
-------------------------------- --------------------------------
......
...@@ -770,18 +770,26 @@ AS_IF([test "${SYS}" != "mingw32"], [ ...@@ -770,18 +770,26 @@ AS_IF([test "${SYS}" != "mingw32"], [
]) ])
AC_SUBST(LIBPTHREAD) AC_SUBST(LIBPTHREAD)
dnl
dnl Check for headers dnl Check for headers
dnl
dnl POSIX 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], [], [], AC_CHECK_HEADERS([net/if.h], [], [],
[ [
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.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 dnl BSD
AC_CHECK_HEADERS([netinet/udplite.h sys/param.h sys/mount.h]) AC_CHECK_HEADERS([netinet/udplite.h sys/param.h sys/mount.h])
dnl GNU/Linux dnl GNU/Linux
AC_CHECK_HEADERS([getopt.h linux/dccp.h linux/magic.h mntent.h sys/eventfd.h]) AC_CHECK_HEADERS([getopt.h linux/dccp.h linux/magic.h mntent.h sys/eventfd.h])
dnl MacOS dnl MacOS
AC_CHECK_HEADERS([xlocale.h]) AC_CHECK_HEADERS([xlocale.h])
......
loggerdir = $(pluginsdir)/logger loggerdir = $(pluginsdir)/logger
libconsole_logger_plugin_la_SOURCES = logger/console.c libconsole_logger_plugin_la_SOURCES = logger/console.c
logger_LTLIBRARIES = libconsole_logger_plugin.la logger_LTLIBRARIES = libconsole_logger_plugin.la
libsyslog_plugin_la_SOURCES = logger/syslog.c
if HAVE_SYSLOG
logger_LTLIBRARIES += libsyslog_plugin.la
endif
/*****************************************************************************
* 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()
...@@ -66,10 +66,6 @@ ...@@ -66,10 +66,6 @@
" </body>\n" \ " </body>\n" \
"</html>\n" "</html>\n"
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#endif
/***************************************************************************** /*****************************************************************************
* intf_sys_t: description and status of log interface * intf_sys_t: description and status of log interface
*****************************************************************************/ *****************************************************************************/
...@@ -77,7 +73,6 @@ struct intf_sys_t ...@@ -77,7 +73,6 @@ struct intf_sys_t
{ {
FILE *p_file; FILE *p_file;
const char *footer; const char *footer;
char *ident;
}; };
/***************************************************************************** /*****************************************************************************
...@@ -88,9 +83,6 @@ static void Close ( vlc_object_t * ); ...@@ -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 TextPrint(void *, int, const vlc_log_t *, const char *, va_list);
static void HtmlPrint(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__ #ifdef __ANDROID__
static void AndroidPrint(void *, int, const vlc_log_t *, const char *, va_list); static void AndroidPrint(void *, int, const vlc_log_t *, const char *, va_list);
#endif #endif
...@@ -99,17 +91,11 @@ static void AndroidPrint(void *, int, const vlc_log_t *, const char *, va_list); ...@@ -99,17 +91,11 @@ static void AndroidPrint(void *, int, const vlc_log_t *, const char *, va_list);
* Module descriptor * Module descriptor
*****************************************************************************/ *****************************************************************************/
static const char *const mode_list[] = { "text", "html" static const char *const mode_list[] = { "text", "html"
#ifdef HAVE_SYSLOG_H
,"syslog"
#endif
#ifdef __ANDROID__ #ifdef __ANDROID__
,"android" ,"android"
#endif #endif
}; };
static const char *const mode_list_text[] = { N_("Text"), "HTML" static const char *const mode_list_text[] = { N_("Text"), "HTML"
#ifdef HAVE_SYSLOG_H
, "syslog"
#endif
#ifdef __ANDROID__ #ifdef __ANDROID__
,"android" ,"android"
#endif #endif
...@@ -118,39 +104,6 @@ static const char *const mode_list_text[] = { N_("Text"), "HTML" ...@@ -118,39 +104,6 @@ static const char *const mode_list_text[] = { N_("Text"), "HTML"
#define LOGMODE_TEXT N_("Log format") #define LOGMODE_TEXT N_("Log format")
#define LOGMODE_LONGTEXT N_("Specify the logging 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_TEXT N_("Verbosity")
#define LOGVERBOSE_LONGTEXT N_("Select the verbosity to use for log or -1 to " \ #define LOGVERBOSE_LONGTEXT N_("Select the verbosity to use for log or -1 to " \
"use the same verbosity given by --verbose.") "use the same verbosity given by --verbose.")
...@@ -167,13 +120,6 @@ vlc_module_begin () ...@@ -167,13 +120,6 @@ vlc_module_begin ()
add_string( "logmode", "text", LOGMODE_TEXT, LOGMODE_LONGTEXT, add_string( "logmode", "text", LOGMODE_TEXT, LOGMODE_LONGTEXT,
false ) false )
change_string_list( mode_list, mode_list_text ) 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, add_integer( "log-verbose", -1, LOGVERBOSE_TEXT, LOGVERBOSE_LONGTEXT,
false ) false )
...@@ -214,10 +160,6 @@ static int Open( vlc_object_t *p_this ) ...@@ -214,10 +160,6 @@ static int Open( vlc_object_t *p_this )
header = HTML_HEADER; header = HTML_HEADER;
cb = HtmlPrint; cb = HtmlPrint;
} }
#ifdef HAVE_SYSLOG_H
else if( !strcmp( mode, "syslog" ) )
cb = SyslogPrint;
#endif
#ifdef __ANDROID__ #ifdef __ANDROID__
else if( !strcmp( mode, "android" ) ) else if( !strcmp( mode, "android" ) )
cb = AndroidPrint; cb = AndroidPrint;
...@@ -227,52 +169,6 @@ static int Open( vlc_object_t *p_this ) ...@@ -227,52 +169,6 @@ static int Open( vlc_object_t *p_this )
free( mode ); 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__ #ifdef __ANDROID__
if( cb == AndroidPrint ) if( cb == AndroidPrint )
{ {
...@@ -332,14 +228,6 @@ static void Close( vlc_object_t *p_this ) ...@@ -332,14 +228,6 @@ static void Close( vlc_object_t *p_this )
vlc_LogSet( p_intf->p_libvlc, NULL, NULL ); vlc_LogSet( p_intf->p_libvlc, NULL, NULL );
/* Close the log file */ /* 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 ) if( p_sys->p_file )
{ {
fputs( p_sys->footer, 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, ...@@ -412,32 +300,6 @@ static void TextPrint( void *opaque, int type, const vlc_log_t *item,
vlc_restorecancel( canc ); 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, static void HtmlPrint( void *opaque, int type, const vlc_log_t *item,
const char *fmt, va_list ap ) const char *fmt, va_list ap )
{ {
......
...@@ -1040,10 +1040,6 @@ static const char *const ppsz_prefres[] = { ...@@ -1040,10 +1040,6 @@ static const char *const ppsz_prefres[] = {
#define FILE_LOG_LONGTEXT N_( \ #define FILE_LOG_LONGTEXT N_( \
"Log all VLC messages to a text file." ) "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") #define ONEINSTANCE_TEXT N_("Allow only one running instance")
#if defined( _WIN32 ) || defined( __OS2__ ) #if defined( _WIN32 ) || defined( __OS2__ )
#define ONEINSTANCE_LONGTEXT N_( \ #define ONEINSTANCE_LONGTEXT N_( \
...@@ -2040,10 +2036,6 @@ vlc_module_begin () ...@@ -2040,10 +2036,6 @@ vlc_module_begin ()
add_bool( "file-logging", false, FILE_LOG_TEXT, FILE_LOG_LONGTEXT, add_bool( "file-logging", false, FILE_LOG_TEXT, FILE_LOG_LONGTEXT,
true ) true )
#ifdef HAVE_SYSLOG_H
add_bool ( "syslog", false, SYSLOG_TEXT, SYSLOG_LONGTEXT,
true )
#endif
#if defined (_WIN32) || defined (__APPLE__) #if defined (_WIN32) || defined (__APPLE__)
add_obsolete_string( "language" ) /* since 2.1.0 */ add_obsolete_string( "language" ) /* since 2.1.0 */
......
...@@ -455,22 +455,6 @@ dbus_out: ...@@ -455,22 +455,6 @@ dbus_out:
free( psz_modules ); free( psz_modules );
free( psz_control ); 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" ) ) if( var_InheritBool( p_libvlc, "file-logging" ) )
libvlc_InternalAddIntf( p_libvlc, "logger,none" ); libvlc_InternalAddIntf( p_libvlc, "logger,none" );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment