add debugging messages for memory (de)allocation
[swfdec.git] / libswfdec / swfdec_debug.c
blob54eee5cdd8f63a229737c653cda6d8989361a6c3
1 /* Swfdec
2 * Copyright (C) 2003-2006 David Schleef <ds@schleef.org>
3 * 2005-2006 Eric Anholt <eric@anholt.net>
4 * 2006-2007 Benjamin Otte <otte@gnome.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301 USA
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
26 #include <glib.h>
27 #include "swfdec_debug.h"
29 static const char *swfdec_debug_level_names[] = {
30 "NONE ",
31 "ERROR",
32 "FIXME",
33 "WARN ",
34 "INFO ",
35 "DEBUG",
36 "LOG "
39 #ifndef SWFDEC_LEVEL_DEFAULT
40 # define SWFDEC_LEVEL_DEFAULT SWFDEC_LEVEL_FIXME
41 #endif
43 static guint swfdec_debug_level = SWFDEC_LEVEL_DEFAULT;
45 void
46 swfdec_debug_log (guint level, const char *file, const char *function,
47 int line, const char *format, ...)
49 va_list varargs;
50 char *s;
52 if (level > swfdec_debug_level)
53 return;
55 va_start (varargs, format);
56 s = g_strdup_vprintf (format, varargs);
57 va_end (varargs);
59 g_printerr ("SWFDEC: %s: %s(%d): %s: %s\n",
60 swfdec_debug_level_names[level], file, line, function, s);
61 g_free (s);
64 void
65 swfdec_debug_set_level (guint level)
67 if (swfdec_debug_level >= G_N_ELEMENTS (swfdec_debug_level_names))
68 swfdec_debug_level = G_N_ELEMENTS (swfdec_debug_level_names) - 1;
69 else
70 swfdec_debug_level = level;
73 int
74 swfdec_debug_get_level (void)
76 return swfdec_debug_level;