The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

u/logging: Implement optional color logging.

Check if stderr is a tty.

authored by

Lubosz Sarnecki and committed by
Jakob Bornecrantz
8bdff9a6 9ce9fa92

+66 -1
+2
CMakeLists.txt
··· 115 115 # This one is named differently because that's what CTest uses 116 116 option(BUILD_TESTING "Enable building of the test suite?" ON) 117 117 118 + option(XRT_FEATURE_COLOR_LOG "Enable logging in color on supported platforms" ON) 119 + 118 120 cmake_dependent_option(CMAKE_INTERPROCEDURAL_OPTIMIZATION "Enable inter-procedural (link-time) optimization" OFF "HAS_IPO" OFF) 119 121 cmake_dependent_option(XRT_HAVE_WAYLAND "Enable Wayland support" ON "WAYLAND_FOUND AND WAYLAND_SCANNER_FOUND AND WAYLAND_PROTOCOLS_FOUND" OFF) 120 122 cmake_dependent_option(XRT_HAVE_XLIB "Enable xlib support" ON "X11_FOUND" OFF)
+5
meson_options.txt
··· 114 114 description: 'Enable SteamVR Plugin' 115 115 ) 116 116 117 + option('color_log', 118 + type: 'boolean', 119 + value: true, 120 + description: 'Log in color' 121 + )
+53 -1
src/xrt/auxiliary/util/u_logging.c
··· 9 9 10 10 #include "util/u_logging.h" 11 11 #include "xrt/xrt_config_os.h" 12 + #include "xrt/xrt_config_build.h" 12 13 13 14 #include <assert.h> 14 15 #include <stdio.h> ··· 149 150 150 151 151 152 #else 153 + 154 + #include <unistd.h> 155 + 152 156 /* 153 157 * 154 158 * Helper functions. 155 159 * 156 160 */ 157 161 162 + 163 + #ifdef XRT_FEATURE_COLOR_LOG 164 + #define COLOR_TRACE "\033[2m" 165 + #define COLOR_DEBUG "\033[36m" 166 + #define COLOR_INFO "\033[32m" 167 + #define COLOR_WARN "\033[33m" 168 + #define COLOR_ERROR "\033[31m" 169 + #define COLOR_RESET "\033[0m" 170 + 158 171 static void 159 - print_prefix(const char *func, enum u_logging_level level) 172 + print_prefix_color(const char *func, enum u_logging_level level) 173 + { 174 + switch (level) { 175 + case U_LOGGING_TRACE: 176 + fprintf(stderr, COLOR_TRACE "TRACE " COLOR_RESET); 177 + break; 178 + case U_LOGGING_DEBUG: 179 + fprintf(stderr, COLOR_DEBUG "DEBUG " COLOR_RESET); 180 + break; 181 + case U_LOGGING_INFO: 182 + fprintf(stderr, COLOR_INFO " INFO " COLOR_RESET); 183 + break; 184 + case U_LOGGING_WARN: 185 + fprintf(stderr, COLOR_WARN " WARN " COLOR_RESET); 186 + break; 187 + case U_LOGGING_ERROR: 188 + fprintf(stderr, COLOR_ERROR "ERROR " COLOR_RESET); 189 + break; 190 + case U_LOGGING_RAW: break; 191 + default: break; 192 + } 193 + } 194 + #endif 195 + 196 + static void 197 + print_prefix_mono(const char *func, enum u_logging_level level) 160 198 { 161 199 switch (level) { 162 200 case U_LOGGING_TRACE: fprintf(stderr, "TRACE "); break; ··· 167 205 case U_LOGGING_RAW: break; 168 206 default: break; 169 207 } 208 + } 209 + 210 + static void 211 + print_prefix(const char *func, enum u_logging_level level) 212 + { 213 + #ifdef XRT_FEATURE_COLOR_LOG 214 + if (isatty(STDERR_FILENO)) { 215 + print_prefix_color(func, level); 216 + } else { 217 + print_prefix_mono(func, level); 218 + } 219 + #else 220 + print_prefix_mono(func, level); 221 + #endif 170 222 171 223 if (level != U_LOGGING_RAW && func != NULL) { 172 224 fprintf(stderr, "[%s] ", func);
+4
src/xrt/include/xrt/meson.build
··· 121 121 build_conf.set('XRT_FEATURE_SERVICE', true) 122 122 endif 123 123 124 + if get_option('color_log') 125 + build_conf.set('XRT_FEATURE_COLOR_LOG', true) 126 + endif 127 + 124 128 xrt_config_build_h = configure_file( 125 129 output: 'xrt_config_build.h', 126 130 configuration: build_conf,
+2
src/xrt/include/xrt/xrt_config_build.h.cmake_in
··· 24 24 #cmakedefine XRT_FEATURE_OPENXR_LAYER_EQUIRECT2 25 25 26 26 #cmakedefine XRT_FEATURE_OPENXR_LAYER_EQUIRECT1 27 + 28 + #cmakedefine XRT_FEATURE_COLOR_LOG