blob: 396d58cb02ffffd945a351cbef19e10a34eef2a9 [file] [log] [blame]
Marat Dukhan547fa362017-03-03 02:47:26 -05001#include <stdarg.h>
Marat Dukhancf70aee2018-03-24 23:21:02 -07002#include <stdlib.h>
Marat Dukhan547fa362017-03-03 02:47:26 -05003#include <stdio.h>
Marat Dukhanb2fc4ab2018-02-19 22:43:26 -08004#ifndef _WIN32
5 #include <unistd.h>
6#endif
Marat Dukhancf70aee2018-03-24 23:21:02 -07007#ifdef __ANDROID__
8 #include <android/log.h>
9 #define CPUINFO_LOG_TAG "cpuinfo"
10#endif
Marat Dukhan547fa362017-03-03 02:47:26 -050011
12#include <log.h>
13
Marat Dukhancf70aee2018-03-24 23:21:02 -070014#ifndef CPUINFO_LOG_TO_STDIO
15 #ifdef __ANDROID__
16 #define CPUINFO_LOG_TO_STDIO 0
17 #else
18 #define CPUINFO_LOG_TO_STDIO 1
19 #endif
20#endif
21
22void cpuinfo_log_fatal(const char* format, ...) {
23 va_list args;
24 va_start(args, format);
25
26 #if defined(__ANDROID__) && !CPUINFO_LOG_TO_STDIO
27 __android_log_vprint(ANDROID_LOG_FATAL, CPUINFO_LOG_TAG, format, args);
28 #elif defined(__ANDROID__) || defined(_WIN32)
29 fprintf(stderr, "Fatal error: ");
30 vfprintf(stderr, format, args);
31 fprintf(stderr, "\n");
32 fflush(stderr);
33 #else
34 dprintf(STDERR_FILENO, "Error: ");
35 vdprintf(STDERR_FILENO, format, args);
36 dprintf(STDERR_FILENO, "\n");
37 #endif
38
39 va_end(args);
40 abort();
41}
42
Marat Dukhan547fa362017-03-03 02:47:26 -050043#if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_ERROR
44 void cpuinfo_log_error(const char* format, ...) {
45 va_list args;
46 va_start(args, format);
47
Marat Dukhancf70aee2018-03-24 23:21:02 -070048 #if defined(__ANDROID__) && !CPUINFO_LOG_TO_STDIO
49 __android_log_vprint(ANDROID_LOG_ERROR, CPUINFO_LOG_TAG, format, args);
50 #elif defined(__ANDROID__) || defined(_WIN32)
Marat Dukhan59d30712017-05-08 04:43:52 -040051 fprintf(stderr, "Error: ");
52 vfprintf(stderr, format, args);
53 fprintf(stderr, "\n");
54 fflush(stderr);
55 #else
56 dprintf(STDERR_FILENO, "Error: ");
57 vdprintf(STDERR_FILENO, format, args);
58 dprintf(STDERR_FILENO, "\n");
59 #endif
Marat Dukhan547fa362017-03-03 02:47:26 -050060
61 va_end(args);
62 }
63#endif
64
65#if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_WARNING
66 void cpuinfo_log_warning(const char* format, ...) {
67 va_list args;
68 va_start(args, format);
69
Marat Dukhancf70aee2018-03-24 23:21:02 -070070 #if defined(__ANDROID__) && !CPUINFO_LOG_TO_STDIO
71 __android_log_vprint(ANDROID_LOG_WARN, CPUINFO_LOG_TAG, format, args);
72 #elif defined(__ANDROID__) || defined(_WIN32)
Marat Dukhan59d30712017-05-08 04:43:52 -040073 fprintf(stderr, "Warning: ");
74 vfprintf(stderr, format, args);
75 fprintf(stderr, "\n");
76 fflush(stderr);
77 #else
78 dprintf(STDERR_FILENO, "Warning: ");
79 vdprintf(STDERR_FILENO, format, args);
80 dprintf(STDERR_FILENO, "\n");
81 #endif
Marat Dukhan547fa362017-03-03 02:47:26 -050082
83 va_end(args);
84 }
85#endif
86
87#if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_INFO
88 void cpuinfo_log_info(const char* format, ...) {
89 va_list args;
90 va_start(args, format);
91
Marat Dukhancf70aee2018-03-24 23:21:02 -070092 #if defined(__ANDROID__) && !CPUINFO_LOG_TO_STDIO
93 __android_log_vprint(ANDROID_LOG_INFO, CPUINFO_LOG_TAG, format, args);
94 #elif defined(__ANDROID__) || defined(_WIN32)
Marat Dukhana8fb3dd2017-08-09 13:49:39 -070095 printf("Note: ");
Marat Dukhan59d30712017-05-08 04:43:52 -040096 vprintf(format, args);
97 printf("\n");
98 fflush(stdout);
99 #else
100 vdprintf(STDOUT_FILENO, format, args);
101 dprintf(STDOUT_FILENO, "\n");
102 #endif
Marat Dukhan547fa362017-03-03 02:47:26 -0500103
104 va_end(args);
105 }
106#endif
107
108#if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_DEBUG
109 void cpuinfo_log_debug(const char* format, ...) {
110 va_list args;
111 va_start(args, format);
112
Marat Dukhancf70aee2018-03-24 23:21:02 -0700113 #if defined(__ANDROID__) && !CPUINFO_LOG_TO_STDIO
114 __android_log_vprint(ANDROID_LOG_DEBUG, CPUINFO_LOG_TAG, format, args);
115 #elif defined(__ANDROID__) || defined(_WIN32)
Marat Dukhana8fb3dd2017-08-09 13:49:39 -0700116 printf("Debug: ");
Marat Dukhan59d30712017-05-08 04:43:52 -0400117 vprintf(format, args);
118 printf("\n");
119 fflush(stdout);
120 #else
121 vdprintf(STDOUT_FILENO, format, args);
122 dprintf(STDOUT_FILENO, "\n");
123 #endif
Marat Dukhan547fa362017-03-03 02:47:26 -0500124
125 va_end(args);
126 }
127#endif