Move mono_trace to header file
[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_IO_LAYER             = (1<<9),
20         MONO_TRACE_ALL                  = MONO_TRACE_ASSEMBLY |
21                                           MONO_TRACE_TYPE |
22                                           MONO_TRACE_DLLIMPORT |
23                                           MONO_TRACE_GC |
24                                           MONO_TRACE_CONFIG |
25                                           MONO_TRACE_AOT |
26                                           MONO_TRACE_SECURITY |
27                                           MONO_TRACE_THREADPOOL |
28                                           MONO_TRACE_IO_THREADPOOL |
29                                           MONO_TRACE_IO_LAYER
30 } MonoTraceMask;
31
32 extern GLogLevelFlags mono_internal_current_level;
33 extern MonoTraceMask mono_internal_current_mask;
34
35 void 
36 mono_trace_init (void);
37
38 void 
39 mono_trace_cleanup (void);
40
41 void 
42 mono_tracev_inner (GLogLevelFlags level, MonoTraceMask mask, const char *format, va_list args);
43
44 void 
45 mono_trace_set_level (GLogLevelFlags level);
46
47 void 
48 mono_trace_set_mask (MonoTraceMask mask);
49
50 void 
51 mono_trace_push (GLogLevelFlags level, MonoTraceMask mask);
52
53 void 
54 mono_trace_pop (void);
55
56 gboolean
57 mono_trace_is_traced (GLogLevelFlags level, MonoTraceMask mask);
58
59 G_GNUC_UNUSED static void
60 mono_tracev (GLogLevelFlags level, MonoTraceMask mask, const char *format, va_list args)
61 {
62         if(G_UNLIKELY (level <= mono_internal_current_level && mask & mono_internal_current_mask))
63                 mono_tracev_inner (level, mask, format, args);
64 }
65
66 /**
67  * mono_trace:
68  *
69  *      @level: Verbose level of the specified message
70  *      @mask: Type of the specified message
71  *
72  * Traces a new message, depending on the current logging level
73  * and trace mask.
74  */
75 G_GNUC_UNUSED static void
76 mono_trace (GLogLevelFlags level, MonoTraceMask mask, const char *format, ...) 
77 {
78         if(G_UNLIKELY (level <= mono_internal_current_level && mask & mono_internal_current_mask)) {
79                 va_list args;
80                 va_start (args, format);
81                 mono_tracev_inner (level, mask, format, args);
82                 va_end (args);
83         }
84 }
85
86 #ifdef G_HAVE_ISO_VARARGS
87 #define mono_trace_error(...)   mono_trace(G_LOG_LEVEL_ERROR, \
88                                                                                         __VA_ARGS__)
89 #define mono_trace_warning(...) mono_trace(G_LOG_LEVEL_WARNING, \
90                                                                                         __VA_ARGS__)
91 #define mono_trace_message(...) mono_trace(G_LOG_LEVEL_MESSAGE, \
92                                                                                         __VA_ARGS__)
93 #elif defined(G_HAVE_GNUC_VARARGS)
94 #define mono_trace_error(format...)     mono_trace(G_LOG_LEVEL_ERROR, \
95                                                                                         format)
96 #define mono_trace_warning(format...) mono_trace(G_LOG_LEVEL_WARNING, \
97                                                                                         format)
98 #define mono_trace_message(format...) mono_trace(G_LOG_LEVEL_MESSAGE, \
99                                                                                         format)
100 #else /* no varargs macros */
101 G_GNUC_UNUSED static void
102 mono_trace_error(MonoTraceMask mask, const char *format, ...)
103 {
104         va_list args;
105         va_start (args, format);
106         mono_tracev(G_LOG_LEVEL_ERROR, mask, format, args);
107         va_end (args);
108 }
109
110 G_GNUC_UNUSED static void
111 mono_trace_warning(MonoTraceMask mask, const char *format, ...)
112 {
113         va_list args;
114         va_start (args, format);
115         mono_tracev(G_LOG_LEVEL_WARNING, mask, format, args);
116         va_end (args);
117 }
118
119 G_GNUC_UNUSED static void
120 mono_trace_message(MonoTraceMask mask, const char *format, ...)
121 {
122         va_list args;
123         va_start (args, format);
124         mono_tracev(G_LOG_LEVEL_MESSAGE, mask, format, args);
125         va_end (args);
126 }
127
128 #endif /* !__GNUC__ */
129
130 #if defined (PLATFORM_ANDROID) || (defined (TARGET_IOS) && defined (TARGET_IOS))
131
132 #define mono_gc_printf(gc_log_file, format, ...) g_log ("mono-gc", G_LOG_LEVEL_MESSAGE, format, ##__VA_ARGS__)
133 #define mono_runtime_printf(format, ...) g_log ("mono-rt", G_LOG_LEVEL_MESSAGE, format "\n", ##__VA_ARGS__)
134 #define mono_runtime_printf_err(format, ...) g_log ("mono-rt", G_LOG_LEVEL_CRITICAL, format "\n", ##__VA_ARGS__)
135 #define mono_runtime_stdout_fflush() do { } while (0)
136
137 #else
138
139 #define mono_gc_printf(gc_log_file, format, ...) do {   \
140         fprintf (gc_log_file, format, ##__VA_ARGS__);   \
141         fflush (gc_log_file);   \
142 } while (0)
143
144 #define mono_runtime_printf(format, ...) fprintf (stdout, format "\n", ##__VA_ARGS__)
145 #define mono_runtime_printf_err(format, ...) fprintf (stderr, format "\n", ##__VA_ARGS__)
146 #define mono_runtime_stdout_fflush() do { fflush (stdout); } while (0)
147
148 #endif
149
150
151 G_END_DECLS
152
153 #endif /* __MONO_LOGGER_INTERNAL_H__ */