-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor logging and remove dependency on clog
- Loading branch information
1 parent
6481e8b
commit 3dc3103
Showing
4 changed files
with
313 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,103 @@ | ||
#pragma once | ||
|
||
#include <inttypes.h> | ||
#include <stdarg.h> | ||
#include <stdlib.h> | ||
|
||
#include <clog.h> | ||
#ifndef CPUINFO_LOG_LEVEL | ||
#error "Undefined CPUINFO_LOG_LEVEL" | ||
#endif | ||
|
||
#define CPUINFO_LOG_DEBUG_PARSERS 0 | ||
#define CPUINFO_LOG_NONE 0 | ||
#define CPUINFO_LOG_FATAL 1 | ||
#define CPUINFO_LOG_ERROR 2 | ||
#define CPUINFO_LOG_WARNING 3 | ||
#define CPUINFO_LOG_INFO 4 | ||
#define CPUINFO_LOG_DEBUG 5 | ||
|
||
#ifndef CPUINFO_LOG_LEVEL | ||
#define CPUINFO_LOG_LEVEL CLOG_ERROR | ||
#ifndef CPUINFO_LOG_DEBUG_PARSERS | ||
#define CPUINFO_LOG_DEBUG_PARSERS 0 | ||
#endif | ||
|
||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_DEBUG | ||
void cpuinfo_vlog_debug(const char* format, va_list args); | ||
#endif | ||
|
||
#if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_INFO | ||
void cpuinfo_vlog_info(const char* format, va_list args); | ||
#endif | ||
|
||
#if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_WARNING | ||
void cpuinfo_vlog_warning(const char* format, va_list args); | ||
#endif | ||
|
||
CLOG_DEFINE_LOG_DEBUG(cpuinfo_log_debug, "cpuinfo", CPUINFO_LOG_LEVEL); | ||
CLOG_DEFINE_LOG_INFO(cpuinfo_log_info, "cpuinfo", CPUINFO_LOG_LEVEL); | ||
CLOG_DEFINE_LOG_WARNING(cpuinfo_log_warning, "cpuinfo", CPUINFO_LOG_LEVEL); | ||
CLOG_DEFINE_LOG_ERROR(cpuinfo_log_error, "cpuinfo", CPUINFO_LOG_LEVEL); | ||
CLOG_DEFINE_LOG_FATAL(cpuinfo_log_fatal, "cpuinfo", CPUINFO_LOG_LEVEL); | ||
#if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_ERROR | ||
void cpuinfo_vlog_error(const char* format, va_list args); | ||
#endif | ||
|
||
#if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_FATAL | ||
void cpuinfo_vlog_fatal(const char* format, va_list args); | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
} // extern "C" | ||
#endif | ||
|
||
#ifndef CPUINFO_LOG_ARGUMENTS_FORMAT | ||
#ifdef __GNUC__ | ||
#define CPUINFO_LOG_ARGUMENTS_FORMAT __attribute__((__format__(__printf__, 1, 2))) | ||
#else | ||
#define CPUINFO_LOG_ARGUMENTS_FORMAT | ||
#endif | ||
#endif | ||
|
||
CPUINFO_LOG_ARGUMENTS_FORMAT inline static void cpuinfo_log_debug(const char* format, ...) { | ||
#if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_DEBUG | ||
va_list args; | ||
va_start(args, format); | ||
cpuinfo_vlog_debug(format, args); | ||
va_end(args); | ||
#endif | ||
} | ||
|
||
CPUINFO_LOG_ARGUMENTS_FORMAT inline static void cpuinfo_log_info(const char* format, ...) { | ||
#if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_INFO | ||
va_list args; | ||
va_start(args, format); | ||
cpuinfo_vlog_info(format, args); | ||
va_end(args); | ||
#endif | ||
} | ||
|
||
CPUINFO_LOG_ARGUMENTS_FORMAT inline static void cpuinfo_log_warning(const char* format, ...) { | ||
#if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_WARNING | ||
va_list args; | ||
va_start(args, format); | ||
cpuinfo_vlog_warning(format, args); | ||
va_end(args); | ||
#endif | ||
} | ||
|
||
CPUINFO_LOG_ARGUMENTS_FORMAT inline static void cpuinfo_log_error(const char* format, ...) { | ||
#if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_ERROR | ||
va_list args; | ||
va_start(args, format); | ||
cpuinfo_vlog_error(format, args); | ||
va_end(args); | ||
#endif | ||
} | ||
|
||
CPUINFO_LOG_ARGUMENTS_FORMAT inline static void cpuinfo_log_fatal(const char* format, ...) { | ||
#if CPUINFO_LOG_LEVEL >= CPUINFO_LOG_FATAL | ||
va_list args; | ||
va_start(args, format); | ||
cpuinfo_vlog_fatal(format, args); | ||
va_end(args); | ||
#endif | ||
abort(); | ||
} |
Oops, something went wrong.