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