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

libvlc: helper to log to a FILE

parent f7260e64
...@@ -56,11 +56,13 @@ ...@@ -56,11 +56,13 @@
# define LIBVLC_DEPRECATED # define LIBVLC_DEPRECATED
#endif #endif
#include <stdio.h>
#include <stdarg.h>
# ifdef __cplusplus # ifdef __cplusplus
extern "C" { extern "C" {
# endif # endif
#include <stdarg.h>
#include <vlc/libvlc_structures.h> #include <vlc/libvlc_structures.h>
/** \defgroup libvlc_core LibVLC core /** \defgroup libvlc_core LibVLC core
...@@ -370,6 +372,15 @@ typedef struct libvlc_log_subscriber ...@@ -370,6 +372,15 @@ typedef struct libvlc_log_subscriber
LIBVLC_API void libvlc_log_subscribe( libvlc_log_subscriber_t *sub, LIBVLC_API void libvlc_log_subscribe( libvlc_log_subscriber_t *sub,
libvlc_log_cb cb, void *data ); libvlc_log_cb cb, void *data );
/**
* Registers a logging callback to a file.
* @param stream FILE pointer opened for writing
* (the FILE pointer must remain valid until libvlc_log_unsubscribe())
*/
LIBVLC_API void libvlc_log_subscribe_file( libvlc_log_subscriber_t *sub,
FILE *stream );
/** /**
* Deregisters a logging callback from LibVLC. * Deregisters a logging callback from LibVLC.
* This function is thread-safe. * This function is thread-safe.
......
...@@ -113,6 +113,25 @@ void libvlc_log_unsubscribe( libvlc_log_subscriber_t *sub ) ...@@ -113,6 +113,25 @@ void libvlc_log_unsubscribe( libvlc_log_subscriber_t *sub )
vlc_rwlock_unlock (&log_lock); vlc_rwlock_unlock (&log_lock);
} }
/*** Helpers for logging to files ***/
static void libvlc_log_file (void *data, int level, const char *fmt,
va_list ap)
{
FILE *stream = data;
flockfile (stream);
vfprintf (stream, fmt, ap);
fputc ('\n', stream);
funlockfile (stream);
(void) level;
}
void libvlc_log_subscribe_file (libvlc_log_subscriber_t *sub, FILE *stream)
{
libvlc_log_subscribe (sub, libvlc_log_file, stream);
}
/*** Stubs for the old interface ***/
unsigned libvlc_get_log_verbosity( const libvlc_instance_t *p_instance ) unsigned libvlc_get_log_verbosity( const libvlc_instance_t *p_instance )
{ {
(void) p_instance; (void) p_instance;
......
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