demux: heif: refactor extents reading
[vlc.git] / lib / log.c
blob1265abe240dafcc4f090c806c75120bf1f07f649
1 /*****************************************************************************
2 * log.c: libvlc new API log functions
3 *****************************************************************************
4 * Copyright (C) 2005 VLC authors and VideoLAN
6 * $Id$
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 *****************************************************************************/
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
29 #include <assert.h>
30 #include <vlc/vlc.h>
31 #include "libvlc_internal.h"
32 #include <vlc_common.h>
33 #include <vlc_interface.h>
35 /*** Logging core dispatcher ***/
37 void libvlc_log_get_context(const libvlc_log_t *ctx,
38 const char **restrict module,
39 const char **restrict file,
40 unsigned *restrict line)
42 if (module != NULL)
43 *module = ctx->psz_module;
44 if (file != NULL)
45 *file = ctx->file;
46 if (line != NULL)
47 *line = ctx->line;
50 void libvlc_log_get_object(const libvlc_log_t *ctx,
51 const char **restrict name,
52 const char **restrict header,
53 uintptr_t *restrict id)
55 if (name != NULL)
56 *name = (ctx->psz_object_type != NULL)
57 ? ctx->psz_object_type : "generic";
58 if (header != NULL)
59 *header = ctx->psz_header;
60 if (id != NULL)
61 *id = ctx->i_object_id;
64 static void libvlc_logf (void *data, int level, const vlc_log_t *item,
65 const char *fmt, va_list ap)
67 libvlc_instance_t *inst = data;
69 switch (level)
71 case VLC_MSG_INFO: level = LIBVLC_NOTICE; break;
72 case VLC_MSG_ERR: level = LIBVLC_ERROR; break;
73 case VLC_MSG_WARN: level = LIBVLC_WARNING; break;
74 case VLC_MSG_DBG: level = LIBVLC_DEBUG; break;
77 inst->log.cb (inst->log.data, level, item, fmt, ap);
80 static const struct vlc_logger_operations libvlc_log_ops = {
81 libvlc_logf, NULL
84 void libvlc_log_unset (libvlc_instance_t *inst)
86 vlc_LogSet (inst->p_libvlc_int, NULL, NULL);
89 void libvlc_log_set (libvlc_instance_t *inst, libvlc_log_cb cb, void *data)
91 libvlc_log_unset (inst); /* <- Barrier before modifying the callback */
92 inst->log.cb = cb;
93 inst->log.data = data;
94 vlc_LogSet(inst->p_libvlc_int, &libvlc_log_ops, inst);
97 /*** Helpers for logging to files ***/
98 static void libvlc_log_file (void *data, int level, const libvlc_log_t *log,
99 const char *fmt, va_list ap)
101 FILE *stream = data;
103 flockfile (stream);
104 vfprintf (stream, fmt, ap);
105 fputc ('\n', stream);
106 funlockfile (stream);
107 (void) level; (void) log;
110 void libvlc_log_set_file (libvlc_instance_t *inst, FILE *stream)
112 libvlc_log_set (inst, libvlc_log_file, stream);