2008-06-05 Andreas Faerber <andreas.faerber@web.de>
[mono.git] / eglib / src / goutput.c
1 /*
2  * Output and debugging functions
3  *
4  * Author:
5  *   Miguel de Icaza (miguel@novell.com)
6  *
7  * (C) 2006 Novell, Inc.
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  */
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <glib.h>
30
31 /* The current fatal levels, error is always fatal */
32 static GLogLevelFlags fatal = G_LOG_LEVEL_ERROR;
33
34 void
35 g_print (const gchar *format, ...)
36 {
37         va_list args;
38
39         va_start (args, format);
40         vprintf (format, args);
41         va_end (args);
42 }
43
44 GLogLevelFlags
45 g_log_set_always_fatal (GLogLevelFlags fatal_mask)
46 {
47         GLogLevelFlags old_fatal = fatal;
48
49         fatal |= fatal_mask;
50         
51         return old_fatal;
52 }
53
54 GLogLevelFlags
55 g_log_set_fatal_mask (const gchar *log_domain, GLogLevelFlags fatal_mask)
56 {
57         /*
58          * Mono does not use a G_LOG_DOMAIN currently, so we just assume things are fatal
59          * if we decide to set G_LOG_DOMAIN (we probably should) we should implement
60          * this.
61          */
62         return fatal_mask;
63 }
64
65 void
66 g_logv (const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, va_list args)
67 {
68         char *msg;
69         
70         vasprintf (&msg, format, args);
71         printf ("%s%s%s",
72                 log_domain != NULL ? log_domain : "",
73                 log_domain != NULL ? ": " : "",
74                 msg);
75         free (msg);
76         if (log_level & fatal)
77                 abort ();
78 }
79
80 void
81 g_log (const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, ...)
82 {
83         char *fmt;
84         va_list args;
85
86         va_start (args, format);
87         g_logv (log_domain, log_level, format, args);
88         fmt = g_strdup_printf (format, args);
89         va_end (args);
90 }
91