[coop] Refactor/reuse mono_value_box_handle/mono_value_box_checked and reduce raw...
[mono-project.git] / mono / utils / mono-logger-internals.h
blob5c24a217e1bbd351cb6dff1b708eeb7ea57ba803
1 /**
2 * \file
3 */
5 #ifndef __MONO_LOGGER_INTERNAL_H__
6 #define __MONO_LOGGER_INTERNAL_H__
8 #include <glib.h>
9 #include <mono/utils/mono-compiler.h>
10 #include "mono-logger.h"
12 G_BEGIN_DECLS
14 typedef enum {
15 MONO_TRACE_ASSEMBLY = 1 << 0,
16 MONO_TRACE_TYPE = 1 << 1,
17 MONO_TRACE_DLLIMPORT = 1 << 2,
18 MONO_TRACE_GC = 1 << 3,
19 MONO_TRACE_CONFIG = 1 << 4,
20 MONO_TRACE_AOT = 1 << 5,
21 MONO_TRACE_SECURITY = 1 << 6,
22 MONO_TRACE_THREADPOOL = 1 << 7,
23 MONO_TRACE_IO_SELECTOR = 1 << 8,
24 MONO_TRACE_IO_LAYER_PROCESS = 1 << 9,
25 MONO_TRACE_IO_LAYER_SOCKET = 1 << 10,
26 MONO_TRACE_IO_LAYER_FILE = 1 << 11,
27 MONO_TRACE_IO_LAYER_EVENT = 1 << 12,
28 MONO_TRACE_IO_LAYER_SEMAPHORE = 1 << 13,
29 MONO_TRACE_IO_LAYER_MUTEX = 1 << 14,
30 MONO_TRACE_IO_LAYER_HANDLE = 1 << 15,
31 MONO_TRACE_TAILCALL = 1 << 16,
32 MONO_TRACE_PROFILER = 1 << 17,
33 } MonoTraceMask;
35 MONO_API_DATA GLogLevelFlags mono_internal_current_level;
36 MONO_API_DATA MonoTraceMask mono_internal_current_mask;
38 MONO_API void
39 mono_trace_init (void);
41 void
42 mono_trace_cleanup (void);
44 MONO_API void
45 mono_tracev_inner (GLogLevelFlags level, MonoTraceMask mask, const char *format, va_list args);
47 void
48 mono_trace_set_level (GLogLevelFlags level);
50 void
51 mono_trace_set_mask (MonoTraceMask mask);
53 void
54 mono_trace_push (GLogLevelFlags level, MonoTraceMask mask);
56 void
57 mono_trace_pop (void);
59 gboolean
60 mono_trace_is_traced (GLogLevelFlags level, MonoTraceMask mask);
62 #define MONO_TRACE_IS_TRACED(level, mask) \
63 G_UNLIKELY ((level) <= mono_internal_current_level && ((mask) & mono_internal_current_mask))
65 G_GNUC_UNUSED static void
66 mono_tracev (GLogLevelFlags level, MonoTraceMask mask, const char *format, va_list args)
68 if (MONO_TRACE_IS_TRACED (level, mask))
69 mono_tracev_inner (level, mask, format, args);
72 /**
73 * mono_trace:
75 * @level: Verbose level of the specified message
76 * @mask: Type of the specified message
78 * Traces a new message, depending on the current logging level
79 * and trace mask.
81 G_GNUC_UNUSED MONO_ATTR_FORMAT_PRINTF(3,4) static void
82 mono_trace (GLogLevelFlags level, MonoTraceMask mask, const char *format, ...)
84 if (MONO_TRACE_IS_TRACED (level, mask)) {
85 va_list args;
86 va_start (args, format);
87 mono_tracev_inner (level, mask, format, args);
88 va_end (args);
92 // __VA_ARGS__ is never empty, so a comma before it is always correct.
93 #define mono_trace_error(...) (mono_trace (G_LOG_LEVEL_ERROR, __VA_ARGS__))
94 #define mono_trace_warning(...) (mono_trace (G_LOG_LEVEL_WARNING, __VA_ARGS__))
95 #define mono_trace_message(...) (mono_trace (G_LOG_LEVEL_MESSAGE, __VA_ARGS__))
97 #if defined (HOST_ANDROID) || (defined (TARGET_IOS) && defined (TARGET_IOS))
99 #define mono_gc_printf(gc_log_file, format, ...) g_log ("mono-gc", G_LOG_LEVEL_MESSAGE, format, ##__VA_ARGS__)
100 #define mono_runtime_printf(format, ...) g_log ("mono-rt", G_LOG_LEVEL_MESSAGE, format "\n", ##__VA_ARGS__)
101 #define mono_runtime_printf_err(format, ...) g_log ("mono-rt", G_LOG_LEVEL_CRITICAL, format "\n", ##__VA_ARGS__)
102 #define mono_profiler_printf(format, ...) g_log ("mono-prof", G_LOG_LEVEL_MESSAGE, format "\n", ##__VA_ARGS__)
103 #define mono_profiler_printf_err(format, ...) g_log ("mono-prof", G_LOG_LEVEL_CRITICAL, format "\n", ##__VA_ARGS__)
104 #define mono_runtime_stdout_fflush() do { } while (0)
106 #else
108 #define mono_gc_printf(gc_log_file, format, ...) do { \
109 fprintf (gc_log_file, format, ##__VA_ARGS__); \
110 fflush (gc_log_file); \
111 } while (0)
113 #define mono_runtime_printf(format, ...) fprintf (stdout, format "\n", ##__VA_ARGS__)
114 #define mono_runtime_printf_err(format, ...) fprintf (stderr, format "\n", ##__VA_ARGS__)
115 #define mono_profiler_printf(format, ...) fprintf (stdout, format "\n", ##__VA_ARGS__)
116 #define mono_profiler_printf_err(format, ...) fprintf (stderr, format "\n", ##__VA_ARGS__)
117 #define mono_runtime_stdout_fflush() do { fflush (stdout); } while (0)
119 #endif
121 /* Internal logging API */
122 typedef void (*MonoLoggerOpen) (const char *, void *);
123 typedef void (*MonoLoggerWrite) (const char *, GLogLevelFlags, mono_bool, const char *);
124 typedef void (*MonoLoggerClose) (void);
126 typedef struct {
127 MonoLoggerOpen opener; /* Routine to open logging */
128 MonoLoggerWrite writer; /* Routine to write log data */
129 MonoLoggerClose closer; /* Routine to close logging */
130 char *dest; /* Log destination */
131 void *user_data; /* User data from legacy handler */
132 mono_bool header; /* Whether we want pid/time/date in log message */
133 } MonoLogCallParm;
135 void mono_trace_set_log_handler_internal (MonoLogCallParm *callback, void *user_data);
136 void mono_trace_set_logdest_string (const char *value);
137 void mono_trace_set_logheader_string (const char *value);
139 void mono_log_open_syslog (const char *, void *);
140 void mono_log_write_syslog (const char *, GLogLevelFlags, mono_bool, const char *);
141 void mono_log_close_syslog (void);
143 void mono_log_open_logfile (const char *, void *);
144 void mono_log_write_logfile (const char *, GLogLevelFlags, mono_bool, const char *);
145 void mono_log_close_logfile (void);
147 #if HOST_ANDROID
148 void mono_log_open_logcat (const char *path, void *userData);
149 void mono_log_write_logcat (const char *log_domain, GLogLevelFlags level, mono_bool hdr, const char *message);
150 void mono_log_close_logcat (void);
151 #endif
153 #if defined(HOST_IOS)
154 void mono_log_open_asl (const char *path, void *userData);
155 void mono_log_write_asl (const char *log_domain, GLogLevelFlags level, mono_bool hdr, const char *message);
156 void mono_log_close_asl (void);
157 #endif
159 void mono_log_open_recorder (const char *path, void *userData);
160 void mono_log_write_recorder (const char *log_domain, GLogLevelFlags level, mono_bool hdr, const char *message);
161 void mono_log_close_recorder (void);
162 void mono_log_dump_recorder (void);
164 G_END_DECLS
166 #endif /* __MONO_LOGGER_INTERNAL_H__ */