MCPcopy Create free account
hub / github.com/StereoKit/StereoKit / log_write

Function log_write

StereoKitC/log.cpp:130–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128///////////////////////////////////////////
129
130void log_write(log_ level, const char *text) {
131 if (level < log_filter)
132 return;
133
134 const char* tag = "";
135 const char* color = "";
136 switch (level) {
137 case log_none: return;
138 case log_diagnostic: tag = "diagnostic"; color = log_colorcodes[8]; break;
139 case log_inform: tag = "info"; color = log_colorcodes[12]; break;
140 case log_warning: tag = "warning"; color = log_colorcodes[6]; break;
141 case log_error: tag = "error"; color = log_colorcodes[2]; break;
142 default: break;
143 }
144
145 int32_t text_len = 0;
146 int32_t color_tags = log_colors == log_colors_ansi ? log_count_color_tags(text, &text_len) : 0;
147
148 // Set up some memory if we have color tags we need to replace
149 char* replace_buffer = nullptr;
150 if (color_tags > 0)
151 replace_buffer = sk_stack_alloc_t(char, (text_len - color_tags*7) + color_tags * 8 + 1);
152
153#if defined(SK_OS_WINDOWS) || defined(SK_OS_LINUX)
154 const char* colored_text = text;
155 if (color_tags > 0) {
156 log_replace_colors(text, replace_buffer, log_tags, log_colorcodes, _countof(log_tags), sizeof(LOG_C_CLEAR) - 1);
157 colored_text = replace_buffer;
158 }
159
160 printf("[SK %s%s" LOG_C_CLEAR "] %s\n", color, tag, colored_text);
161#endif
162
163 // The remaining outputs don't support colors
164 const char* plain_text = text;
165 if (color_tags > 0) {
166 log_replace_colors(text, replace_buffer, log_tags, nullptr, _countof(log_tags), 0);
167 plain_text = replace_buffer;
168 }
169 for (int32_t i = 0; i < log_listeners.count; i++) {
170 log_listeners[i].callback(log_listeners[i].context, level, plain_text);
171 }
172 platform_debug_output(level, plain_text);
173 if (level == log_error) platform_print_callstack();
174}
175
176///////////////////////////////////////////
177

Callers 7

common_updateFunction · 0.85
_log_writefFunction · 0.85
log_diagFunction · 0.85
log_infoFunction · 0.85
log_warnFunction · 0.85
log_errFunction · 0.85
log_fail_reasonFunction · 0.85

Calls 4

log_count_color_tagsFunction · 0.85
log_replace_colorsFunction · 0.85
platform_debug_outputFunction · 0.50
platform_print_callstackFunction · 0.50

Tested by

no test coverage detected