Merge pull request #2311 from mlancione/master
[mono.git] / mono / utils / mono-logger-internals.h
1 #ifndef __MONO_LOGGER_INTERNAL_H__
2 #define __MONO_LOGGER_INTERNAL_H__
3
4 #include <glib.h>
5 #include "mono-logger.h"
6
7 G_BEGIN_DECLS
8
9 typedef enum {
10         MONO_TRACE_ASSEMBLY             = (1<<0),
11         MONO_TRACE_TYPE                 = (1<<1),
12         MONO_TRACE_DLLIMPORT            = (1<<2),
13         MONO_TRACE_GC                   = (1<<3),
14         MONO_TRACE_CONFIG               = (1<<4),
15         MONO_TRACE_AOT                  = (1<<5),
16         MONO_TRACE_SECURITY             = (1<<6),
17         MONO_TRACE_THREADPOOL           = (1<<7),
18         MONO_TRACE_IO_THREADPOOL        = (1<<8),
19         MONO_TRACE_ALL                  = MONO_TRACE_ASSEMBLY |
20                                           MONO_TRACE_TYPE |
21                                           MONO_TRACE_DLLIMPORT |
22                                           MONO_TRACE_GC |
23                                           MONO_TRACE_CONFIG |
24                                           MONO_TRACE_AOT |
25                                           MONO_TRACE_SECURITY |
26                                           MONO_TRACE_THREADPOOL |
27                                           MONO_TRACE_IO_THREADPOOL
28 } MonoTraceMask;
29
30 void 
31 mono_trace_cleanup (void);
32
33 void 
34 mono_trace (GLogLevelFlags level, MonoTraceMask mask, const char *format, ...);
35
36 void 
37 mono_tracev (GLogLevelFlags level, MonoTraceMask mask, const char *format, va_list args);
38
39 void 
40 mono_trace_set_level (GLogLevelFlags level);
41
42 void 
43 mono_trace_set_mask (MonoTraceMask mask);
44
45 void 
46 mono_trace_push (GLogLevelFlags level, MonoTraceMask mask);
47
48 void 
49 mono_trace_pop (void);
50
51 gboolean
52 mono_trace_is_traced (GLogLevelFlags level, MonoTraceMask mask);
53
54 #ifdef G_HAVE_ISO_VARARGS
55 #define mono_trace_error(...)   mono_trace(G_LOG_LEVEL_ERROR, \
56                                                                                         __VA_ARGS__)
57 #define mono_trace_warning(...) mono_trace(G_LOG_LEVEL_WARNING, \
58                                                                                         __VA_ARGS__)
59 #define mono_trace_message(...) mono_trace(G_LOG_LEVEL_MESSAGE, \
60                                                                                         __VA_ARGS__)
61 #elif defined(G_HAVE_GNUC_VARARGS)
62 #define mono_trace_error(format...)     mono_trace(G_LOG_LEVEL_ERROR, \
63                                                                                         format)
64 #define mono_trace_warning(format...) mono_trace(G_LOG_LEVEL_WARNING, \
65                                                                                         format)
66 #define mono_trace_message(format...) mono_trace(G_LOG_LEVEL_MESSAGE, \
67                                                                                         format)
68 #else /* no varargs macros */
69 G_GNUC_UNUSED static void
70 mono_trace_error(MonoTraceMask mask, const char *format, ...)
71 {
72         va_list args;
73         va_start (args, format);
74         mono_tracev(G_LOG_LEVEL_ERROR, mask, format, args);
75         va_end (args);
76 }
77
78 G_GNUC_UNUSED static void
79 mono_trace_warning(MonoTraceMask mask, const char *format, ...)
80 {
81         va_list args;
82         va_start (args, format);
83         mono_tracev(G_LOG_LEVEL_WARNING, mask, format, args);
84         va_end (args);
85 }
86
87 G_GNUC_UNUSED static void
88 mono_trace_message(MonoTraceMask mask, const char *format, ...)
89 {
90         va_list args;
91         va_start (args, format);
92         mono_tracev(G_LOG_LEVEL_MESSAGE, mask, format, args);
93         va_end (args);
94 }
95
96 #endif /* !__GNUC__ */
97
98 #if defined (PLATFORM_ANDROID) || (defined (TARGET_IOS) && defined (TARGET_IOS))
99
100 #define mono_gc_printf(gc_log_file, format, ...) g_log ("mono-gc", G_LOG_LEVEL_MESSAGE, format, ##__VA_ARGS__)
101 #define mono_runtime_printf(format, ...) g_log ("mono-rt", G_LOG_LEVEL_MESSAGE, format "\n", ##__VA_ARGS__)
102 #define mono_runtime_printf_err(format, ...) g_log ("mono-rt", G_LOG_LEVEL_CRITICAL, format "\n", ##__VA_ARGS__)
103 #define mono_runtime_stdout_fflush() do { } while (0)
104
105 #else
106
107 #define mono_gc_printf(gc_log_file, format, ...) do {   \
108         fprintf (gc_log_file, format, ##__VA_ARGS__);   \
109         fflush (gc_log_file);   \
110 } while (0)
111
112 #define mono_runtime_printf(format, ...) fprintf (stdout, format "\n", ##__VA_ARGS__)
113 #define mono_runtime_printf_err(format, ...) fprintf (stderr, format "\n", ##__VA_ARGS__)
114 #define mono_runtime_stdout_fflush() do { fflush (stdout); } while (0)
115
116 #endif
117
118
119 G_END_DECLS
120
121 #endif /* __MONO_LOGGER_INTERNAL_H__ */