• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #pragma once
2 
3 #include <inttypes.h>
4 #include <stdarg.h>
5 #include <stdlib.h>
6 
7 #ifndef CPUINFO_LOG_LEVEL
8 #error "Undefined CPUINFO_LOG_LEVEL"
9 #endif
10 
11 #define CPUINFO_LOG_NONE 0
12 #define CPUINFO_LOG_FATAL 1
13 #define CPUINFO_LOG_ERROR 2
14 #define CPUINFO_LOG_WARNING 3
15 #define CPUINFO_LOG_INFO 4
16 #define CPUINFO_LOG_DEBUG 5
17 
18 #ifndef CPUINFO_LOG_DEBUG_PARSERS
19 #define CPUINFO_LOG_DEBUG_PARSERS 0
20 #endif
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_DEBUG
27 void cpuinfo_vlog_debug(const char* format, va_list args);
28 #endif
29 
30 #if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_INFO
31 void cpuinfo_vlog_info(const char* format, va_list args);
32 #endif
33 
34 #if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_WARNING
35 void cpuinfo_vlog_warning(const char* format, va_list args);
36 #endif
37 
38 #if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_ERROR
39 void cpuinfo_vlog_error(const char* format, va_list args);
40 #endif
41 
42 #if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_FATAL
43 void cpuinfo_vlog_fatal(const char* format, va_list args);
44 #endif
45 
46 #ifdef __cplusplus
47 } // extern "C"
48 #endif
49 
50 #ifndef CPUINFO_LOG_ARGUMENTS_FORMAT
51 #ifdef __GNUC__
52 #define CPUINFO_LOG_ARGUMENTS_FORMAT __attribute__((__format__(__printf__, 1, 2)))
53 #else
54 #define CPUINFO_LOG_ARGUMENTS_FORMAT
55 #endif
56 #endif
57 
cpuinfo_log_debug(const char * format,...)58 CPUINFO_LOG_ARGUMENTS_FORMAT inline static void cpuinfo_log_debug(const char* format, ...) {
59 #if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_DEBUG
60 	va_list args;
61 	va_start(args, format);
62 	cpuinfo_vlog_debug(format, args);
63 	va_end(args);
64 #endif
65 }
66 
cpuinfo_log_info(const char * format,...)67 CPUINFO_LOG_ARGUMENTS_FORMAT inline static void cpuinfo_log_info(const char* format, ...) {
68 #if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_INFO
69 	va_list args;
70 	va_start(args, format);
71 	cpuinfo_vlog_info(format, args);
72 	va_end(args);
73 #endif
74 }
75 
cpuinfo_log_warning(const char * format,...)76 CPUINFO_LOG_ARGUMENTS_FORMAT inline static void cpuinfo_log_warning(const char* format, ...) {
77 #if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_WARNING
78 	va_list args;
79 	va_start(args, format);
80 	cpuinfo_vlog_warning(format, args);
81 	va_end(args);
82 #endif
83 }
84 
cpuinfo_log_error(const char * format,...)85 CPUINFO_LOG_ARGUMENTS_FORMAT inline static void cpuinfo_log_error(const char* format, ...) {
86 #if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_ERROR
87 	va_list args;
88 	va_start(args, format);
89 	cpuinfo_vlog_error(format, args);
90 	va_end(args);
91 #endif
92 }
93 
cpuinfo_log_fatal(const char * format,...)94 CPUINFO_LOG_ARGUMENTS_FORMAT inline static void cpuinfo_log_fatal(const char* format, ...) {
95 #if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_FATAL
96 	va_list args;
97 	va_start(args, format);
98 	cpuinfo_vlog_fatal(format, args);
99 	va_end(args);
100 #endif
101 	abort();
102 }