diff options
author | Marat Dukhan <maratek@gmail.com> | 2018-06-04 02:40:10 -0700 |
---|---|---|
committer | Marat Dukhan <maratek@gmail.com> | 2018-06-04 02:40:10 -0700 |
commit | ad935b502e8dadeaf533d5c7b1b0b24d264b0241 (patch) | |
tree | b454e16f5a06558871bf513c4f2d4b60317f91e3 /src | |
parent | 860243e5b96705e9fc81a7537417bb43b25a57ef (diff) | |
download | cpuinfo-ad935b502e8dadeaf533d5c7b1b0b24d264b0241.tar.gz |
Refactor logging code
Diffstat (limited to 'src')
-rw-r--r-- | src/log.c | 127 | ||||
-rw-r--r-- | src/log.h | 54 |
2 files changed, 7 insertions, 174 deletions
diff --git a/src/log.c b/src/log.c deleted file mode 100644 index 396d58c..0000000 --- a/src/log.c +++ /dev/null @@ -1,127 +0,0 @@ -#include <stdarg.h> -#include <stdlib.h> -#include <stdio.h> -#ifndef _WIN32 - #include <unistd.h> -#endif -#ifdef __ANDROID__ - #include <android/log.h> - #define CPUINFO_LOG_TAG "cpuinfo" -#endif - -#include <log.h> - -#ifndef CPUINFO_LOG_TO_STDIO - #ifdef __ANDROID__ - #define CPUINFO_LOG_TO_STDIO 0 - #else - #define CPUINFO_LOG_TO_STDIO 1 - #endif -#endif - -void cpuinfo_log_fatal(const char* format, ...) { - va_list args; - va_start(args, format); - - #if defined(__ANDROID__) && !CPUINFO_LOG_TO_STDIO - __android_log_vprint(ANDROID_LOG_FATAL, CPUINFO_LOG_TAG, format, args); - #elif defined(__ANDROID__) || defined(_WIN32) - fprintf(stderr, "Fatal error: "); - vfprintf(stderr, format, args); - fprintf(stderr, "\n"); - fflush(stderr); - #else - dprintf(STDERR_FILENO, "Error: "); - vdprintf(STDERR_FILENO, format, args); - dprintf(STDERR_FILENO, "\n"); - #endif - - va_end(args); - abort(); -} - -#if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_ERROR - void cpuinfo_log_error(const char* format, ...) { - va_list args; - va_start(args, format); - - #if defined(__ANDROID__) && !CPUINFO_LOG_TO_STDIO - __android_log_vprint(ANDROID_LOG_ERROR, CPUINFO_LOG_TAG, format, args); - #elif defined(__ANDROID__) || defined(_WIN32) - fprintf(stderr, "Error: "); - vfprintf(stderr, format, args); - fprintf(stderr, "\n"); - fflush(stderr); - #else - dprintf(STDERR_FILENO, "Error: "); - vdprintf(STDERR_FILENO, format, args); - dprintf(STDERR_FILENO, "\n"); - #endif - - va_end(args); - } -#endif - -#if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_WARNING - void cpuinfo_log_warning(const char* format, ...) { - va_list args; - va_start(args, format); - - #if defined(__ANDROID__) && !CPUINFO_LOG_TO_STDIO - __android_log_vprint(ANDROID_LOG_WARN, CPUINFO_LOG_TAG, format, args); - #elif defined(__ANDROID__) || defined(_WIN32) - fprintf(stderr, "Warning: "); - vfprintf(stderr, format, args); - fprintf(stderr, "\n"); - fflush(stderr); - #else - dprintf(STDERR_FILENO, "Warning: "); - vdprintf(STDERR_FILENO, format, args); - dprintf(STDERR_FILENO, "\n"); - #endif - - va_end(args); - } -#endif - -#if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_INFO - void cpuinfo_log_info(const char* format, ...) { - va_list args; - va_start(args, format); - - #if defined(__ANDROID__) && !CPUINFO_LOG_TO_STDIO - __android_log_vprint(ANDROID_LOG_INFO, CPUINFO_LOG_TAG, format, args); - #elif defined(__ANDROID__) || defined(_WIN32) - printf("Note: "); - vprintf(format, args); - printf("\n"); - fflush(stdout); - #else - vdprintf(STDOUT_FILENO, format, args); - dprintf(STDOUT_FILENO, "\n"); - #endif - - va_end(args); - } -#endif - -#if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_DEBUG - void cpuinfo_log_debug(const char* format, ...) { - va_list args; - va_start(args, format); - - #if defined(__ANDROID__) && !CPUINFO_LOG_TO_STDIO - __android_log_vprint(ANDROID_LOG_DEBUG, CPUINFO_LOG_TAG, format, args); - #elif defined(__ANDROID__) || defined(_WIN32) - printf("Debug: "); - vprintf(format, args); - printf("\n"); - fflush(stdout); - #else - vdprintf(STDOUT_FILENO, format, args); - dprintf(STDOUT_FILENO, "\n"); - #endif - - va_end(args); - } -#endif @@ -2,56 +2,16 @@ #include <inttypes.h> -#define CPUINFO_LOG_ERROR 1 -#define CPUINFO_LOG_WARNING 2 -#define CPUINFO_LOG_INFO 3 -#define CPUINFO_LOG_DEBUG 4 +#include <clog.h> #define CPUINFO_LOG_DEBUG_PARSERS 0 #ifndef CPUINFO_LOG_LEVEL - #define CPUINFO_LOG_LEVEL CPUINFO_LOG_ERROR + #define CPUINFO_LOG_LEVEL CLOG_ERROR #endif -#ifdef __GNUC__ -__attribute__((__format__(__printf__, 1, 2))) -#endif -#if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_DEBUG - void cpuinfo_log_debug(const char* format, ...); -#else - static inline void cpuinfo_log_debug(const char* format, ...) { } -#endif - -#ifdef __GNUC__ -__attribute__((__format__(__printf__, 1, 2))) -#endif -#if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_INFO - void cpuinfo_log_info(const char* format, ...); -#else - static inline void cpuinfo_log_info(const char* format, ...) { } -#endif - -#ifdef __GNUC__ -__attribute__((__format__(__printf__, 1, 2))) -#endif -#if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_WARNING - void cpuinfo_log_warning(const char* format, ...); -#else - static inline void cpuinfo_log_warning(const char* format, ...) { } -#endif - -#ifdef __GNUC__ -__attribute__((__format__(__printf__, 1, 2))) -#endif -#if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_ERROR - void cpuinfo_log_error(const char* format, ...); -#else - static inline void cpuinfo_log_error(const char* format, ...) { } -#endif - -#if defined(__GNUC__) -__attribute__((__format__(__printf__, 1, 2), __noreturn__)) -#elif defined(_MSC_VER) -__declspec(noreturn) -#endif -void cpuinfo_log_fatal(const char* format, ...); +CLOG_DEFINE_LOG_DEBUG(cpuinfo_, "cpuinfo", CPUINFO_LOG_LEVEL); +CLOG_DEFINE_LOG_INFO(cpuinfo_, "cpuinfo", CPUINFO_LOG_LEVEL); +CLOG_DEFINE_LOG_WARNING(cpuinfo_, "cpuinfo", CPUINFO_LOG_LEVEL); +CLOG_DEFINE_LOG_ERROR(cpuinfo_, "cpuinfo", CPUINFO_LOG_LEVEL); +CLOG_DEFINE_LOG_FATAL(cpuinfo_, "cpuinfo", CPUINFO_LOG_LEVEL); |