1 /*****************************************************************************
2 * log.c: libvlc new API log functions
3 *****************************************************************************
4 * Copyright (C) 2005 VLC authors and VideoLAN
8 * Authors: Damien Fouilleul <damienf@videolan.org>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
30 #include <vlc/libvlc.h>
31 #include "libvlc_internal.h"
32 #include <vlc_common.h>
33 #include <vlc_interface.h>
35 /*** Logging core dispatcher ***/
38 static void libvlc_log (libvlc_instance_t *inst, int level,
39 const libvlc_log_t *ctx, const char *fmt, ...)
44 inst->log.cb (inst->log.data, level, ctx, fmt, ap);
48 static void libvlc_logf (void *data, int level, const vlc_log_t *item,
49 const char *fmt, va_list ap)
53 if (unlikely(vasprintf (&msg, fmt, ap) == -1))
58 case VLC_MSG_INFO: level = LIBVLC_NOTICE; break;
59 case VLC_MSG_ERR: level = LIBVLC_ERROR; break;
60 case VLC_MSG_WARN: level = LIBVLC_WARNING; break;
61 case VLC_MSG_DBG: level = LIBVLC_DEBUG; break;
64 if (item->psz_header != NULL)
65 libvlc_log (data, level, item, "[%p] [%s]: %s %s %s",
66 (void *)item->i_object_id, item->psz_header,
67 item->psz_module, item->psz_object_type, msg);
69 libvlc_log (data, level, item, "[%p]: %s %s %s",
70 (void *)item->i_object_id, item->psz_module,
71 item->psz_object_type, msg);
75 void libvlc_log_unset (libvlc_instance_t *inst)
77 vlc_LogSet (inst->p_libvlc_int, NULL, NULL);
80 void libvlc_log_set (libvlc_instance_t *inst, libvlc_log_cb cb, void *data)
82 libvlc_log_unset (inst); /* <- Barrier before modifying the callback */
84 inst->log.data = data;
85 vlc_LogSet (inst->p_libvlc_int, libvlc_logf, inst);
88 /*** Helpers for logging to files ***/
89 static void libvlc_log_file (void *data, int level, const libvlc_log_t *log,
90 const char *fmt, va_list ap)
95 vfprintf (stream, fmt, ap);
98 (void) level; (void) log;
101 void libvlc_log_set_file (libvlc_instance_t *inst, FILE *stream)
103 libvlc_log_set (inst, libvlc_log_file, stream);
106 /*** Stubs for the old interface ***/
107 unsigned libvlc_get_log_verbosity( const libvlc_instance_t *p_instance )
113 void libvlc_set_log_verbosity( libvlc_instance_t *p_instance, unsigned level )
119 libvlc_log_t *libvlc_log_open( libvlc_instance_t *p_instance )
125 void libvlc_log_close( libvlc_log_t *p_log )
130 unsigned libvlc_log_count( const libvlc_log_t *p_log )
136 void libvlc_log_clear( libvlc_log_t *p_log )
141 libvlc_log_iterator_t *libvlc_log_get_iterator( const libvlc_log_t *p_log )
143 return (p_log != NULL) ? malloc(1) : NULL;
146 void libvlc_log_iterator_free( libvlc_log_iterator_t *p_iter )
151 int libvlc_log_iterator_has_next( const libvlc_log_iterator_t *p_iter )
157 libvlc_log_message_t *libvlc_log_iterator_next( libvlc_log_iterator_t *p_iter,
158 libvlc_log_message_t *buffer )
160 (void) p_iter; (void) buffer;