Prefix LOG and CHECK with AOS_
This prepares us for introducing glog more widely and transitioning
things over where they make sense.
Change-Id: Ic6c208882407bc2153fe875ffc736d66f5c8ade5
diff --git a/aos/logging/logging.h b/aos/logging/logging.h
index 6682098..bd9b103 100644
--- a/aos/logging/logging.h
+++ b/aos/logging/logging.h
@@ -4,14 +4,14 @@
// This file contains the logging client interface. It works with both C and C++
// code.
-#include <stdio.h>
+#include <errno.h>
#include <stdint.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <errno.h>
-#include "aos/macros.h"
#include "aos/libc/aos_strerror.h"
+#include "aos/macros.h"
#ifdef __cplusplus
extern "C" {
@@ -19,16 +19,16 @@
typedef uint8_t log_level;
-#define DECL_LEVELS \
-DECL_LEVEL(DEBUG, 0); /* stuff that gets printed out every cycle */ \
-DECL_LEVEL(INFO, 1); /* things like PosEdge/NegEdge */ \
-/* things that might still work if they happen occasionally */ \
-DECL_LEVEL(WARNING, 2); \
-/*-1 so that vxworks macro of same name will have same effect if used*/ \
-DECL_LEVEL(ERROR, -1); /* errors */ \
-/* serious errors. the logging code will terminate the process/task */ \
-DECL_LEVEL(FATAL, 4); \
-DECL_LEVEL(LOG_UNKNOWN, 5); /* unknown logging level */
+#define DECL_LEVELS \
+ DECL_LEVEL(DEBUG, 0); /* stuff that gets printed out every cycle */ \
+ DECL_LEVEL(INFO, 1); /* things like PosEdge/NegEdge */ \
+ /* things that might still work if they happen occasionally */ \
+ DECL_LEVEL(WARNING, 2); \
+ /*-1 so that vxworks macro of same name will have same effect if used*/ \
+ DECL_LEVEL(ERROR, -1); /* errors */ \
+ /* serious errors. the logging code will terminate the process/task */ \
+ DECL_LEVEL(FATAL, 4); \
+ DECL_LEVEL(LOG_UNKNOWN, 5); /* unknown logging level */
#define DECL_LEVEL(name, value) static const log_level name = value;
DECL_LEVELS;
#undef DECL_LEVEL
@@ -40,14 +40,14 @@
// Actually implements the basic logging call.
// Does not check that level is valid.
void log_do(log_level level, const char *format, ...)
- __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 2, 3)));
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 2, 3)));
void log_cork(int line, const char *function, const char *format, ...)
- __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 4)));
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 4)));
// Implements the uncork logging call.
void log_uncork(int line, const char *function, log_level level,
const char *file, const char *format, ...)
- __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 5, 6)));
+ __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 5, 6)));
#ifdef __cplusplus
}
@@ -64,7 +64,7 @@
#define LOG_SOURCENAME __FILE__
// The basic logging call.
-#define LOG(level, format, args...) \
+#define AOS_LOG(level, format, args...) \
do { \
log_do(level, LOG_SOURCENAME ": " STRINGIFY(__LINE__) ": %s: " format, \
LOG_CURRENT_FUNCTION, ##args); \
@@ -78,39 +78,39 @@
// Same as LOG except appends " due to %d (%s)\n" (formatted with errno and
// aos_strerror(errno)) to the message.
-#define PLOG(level, format, args...) PELOG(level, errno, format, ##args)
+#define AOS_PLOG(level, format, args...) AOS_PELOG(level, errno, format, ##args)
// Like PLOG except allows specifying an error other than errno.
-#define PELOG(level, error_in, format, args...) \
- do { \
- const int error = error_in; \
- LOG(level, format " due to %d (%s)\n", ##args, error, \
- aos_strerror(error)); \
+#define AOS_PELOG(level, error_in, format, args...) \
+ do { \
+ const int error = error_in; \
+ AOS_LOG(level, format " due to %d (%s)\n", ##args, error, \
+ aos_strerror(error)); \
} while (0);
// Allows format to not be a string constant.
-#define LOG_DYNAMIC(level, format, args...) \
- do { \
- static char log_buf[LOG_MESSAGE_LEN]; \
- int ret = snprintf(log_buf, sizeof(log_buf), format, ##args); \
- if (ret < 0 || (uintmax_t)ret >= LOG_MESSAGE_LEN) { \
- LOG(ERROR, "next message was too long so not subbing in args\n"); \
- LOG(level, "%s", format); \
- } else { \
- LOG(level, "%s", log_buf); \
- } \
+#define AOS_LOG_DYNAMIC(level, format, args...) \
+ do { \
+ static char log_buf[LOG_MESSAGE_LEN]; \
+ int ret = snprintf(log_buf, sizeof(log_buf), format, ##args); \
+ if (ret < 0 || (uintmax_t)ret >= LOG_MESSAGE_LEN) { \
+ AOS_LOG(ERROR, "next message was too long so not subbing in args\n"); \
+ AOS_LOG(level, "%s", format); \
+ } else { \
+ AOS_LOG(level, "%s", log_buf); \
+ } \
} while (0)
// Allows "bottling up" multiple log fragments which can then all be logged in
// one message with LOG_UNCORK.
// Calls from a given thread/task will be grouped together.
-#define LOG_CORK(format, args...) \
+#define AOS_LOG_CORK(format, args...) \
do { \
log_cork(__LINE__, LOG_CURRENT_FUNCTION, format, ##args); \
} while (0)
// Actually logs all of the saved up log fragments (including format and args on
// the end).
-#define LOG_UNCORK(level, format, args...) \
+#define AOS_LOG_UNCORK(level, format, args...) \
do { \
log_uncork(__LINE__, LOG_CURRENT_FUNCTION, level, LOG_SOURCENAME, format, \
##args); \
@@ -162,16 +162,16 @@
// controlled by NDEBUG, so the check will be executed regardless of
// compilation mode. Therefore, it is safe to do things like:
// CHECK(fp->Write(x) == 4)
-#define CHECK(condition) \
- if (__builtin_expect(!(condition), 0)) { \
- LOG(FATAL, "CHECK(%s) failed\n", #condition); \
+#define AOS_CHECK(condition) \
+ if (__builtin_expect(!(condition), 0)) { \
+ AOS_LOG(FATAL, "CHECK(%s) failed\n", #condition); \
}
// Helper functions for CHECK_OP macro.
// The (int, int) specialization works around the issue that the compiler
// will not instantiate the template version of the function on values of
// unnamed enum type.
-#define DEFINE_CHECK_OP_IMPL(name, op) \
+#define AOS_DEFINE_CHECK_OP_IMPL(name, op) \
template <typename T1, typename T2> \
inline void LogImpl##name(const T1 &v1, const T2 &v2, \
const char *exprtext) { \
@@ -192,47 +192,47 @@
// base/logging.h provides its own #defines for the simpler names EQ, NE, etc.
// This happens if, for example, those are used as token names in a
// yacc grammar.
-DEFINE_CHECK_OP_IMPL(Check_EQ, ==) // Compilation error with CHECK_EQ(NULL, x)?
-DEFINE_CHECK_OP_IMPL(Check_NE, !=) // Use CHECK(x == NULL) instead.
-DEFINE_CHECK_OP_IMPL(Check_LE, <=)
-DEFINE_CHECK_OP_IMPL(Check_LT, < )
-DEFINE_CHECK_OP_IMPL(Check_GE, >=)
-DEFINE_CHECK_OP_IMPL(Check_GT, > )
+AOS_DEFINE_CHECK_OP_IMPL(Check_EQ, ==) // Compilation error with CHECK_EQ(NULL, x)?
+AOS_DEFINE_CHECK_OP_IMPL(Check_NE, !=) // Use CHECK(x == NULL) instead.
+AOS_DEFINE_CHECK_OP_IMPL(Check_LE, <=)
+AOS_DEFINE_CHECK_OP_IMPL(Check_LT, <)
+AOS_DEFINE_CHECK_OP_IMPL(Check_GE, >=)
+AOS_DEFINE_CHECK_OP_IMPL(Check_GT, >)
-#define CHECK_OP(name, op, val1, val2) \
- ::aos::LogImplCheck##name(val1, val2, \
+#define AOS_CHECK_OP(name, op, val1, val2) \
+ ::aos::LogImplCheck##name(val1, val2, \
STRINGIFY(val1) STRINGIFY(op) STRINGIFY(val2))
-#define CHECK_EQ(val1, val2) CHECK_OP(_EQ, ==, val1, val2)
-#define CHECK_NE(val1, val2) CHECK_OP(_NE, !=, val1, val2)
-#define CHECK_LE(val1, val2) CHECK_OP(_LE, <=, val1, val2)
-#define CHECK_LT(val1, val2) CHECK_OP(_LT, < , val1, val2)
-#define CHECK_GE(val1, val2) CHECK_OP(_GE, >=, val1, val2)
-#define CHECK_GT(val1, val2) CHECK_OP(_GT, > , val1, val2)
+#define AOS_CHECK_EQ(val1, val2) AOS_CHECK_OP(_EQ, ==, val1, val2)
+#define AOS_CHECK_NE(val1, val2) AOS_CHECK_OP(_NE, !=, val1, val2)
+#define AOS_CHECK_LE(val1, val2) AOS_CHECK_OP(_LE, <=, val1, val2)
+#define AOS_CHECK_LT(val1, val2) AOS_CHECK_OP(_LT, <, val1, val2)
+#define AOS_CHECK_GE(val1, val2) AOS_CHECK_OP(_GE, >=, val1, val2)
+#define AOS_CHECK_GT(val1, val2) AOS_CHECK_OP(_GT, >, val1, val2)
// A small helper for CHECK_NOTNULL().
template <typename T>
-inline T* CheckNotNull(const char *value_name, T *t) {
+inline T *CheckNotNull(const char *value_name, T *t) {
if (t == NULL) {
- LOG(FATAL, "'%s' must not be NULL\n", value_name);
+ AOS_LOG(FATAL, "'%s' must not be NULL\n", value_name);
}
return t;
}
// Check that the input is non NULL. This very useful in constructor
// initializer lists.
-#define CHECK_NOTNULL(val) ::aos::CheckNotNull(STRINGIFY(val), val)
+#define AOS_CHECK_NOTNULL(val) ::aos::CheckNotNull(STRINGIFY(val), val)
inline int CheckSyscall(const char *syscall_string, int value) {
if (__builtin_expect(value == -1, false)) {
- PLOG(FATAL, "%s failed", syscall_string);
+ AOS_PLOG(FATAL, "%s failed", syscall_string);
}
return value;
}
inline void CheckSyscallReturn(const char *syscall_string, int value) {
if (__builtin_expect(value != 0, false)) {
- PELOG(FATAL, value, "%s failed", syscall_string);
+ AOS_PELOG(FATAL, value, "%s failed", syscall_string);
}
}
@@ -240,16 +240,17 @@
// useful for quickly checking syscalls where it's not very useful to print out
// the values of any of the arguments. Returns the result otherwise.
//
-// Example: const int fd = PCHECK(open("/tmp/whatever", O_WRONLY))
-#define PCHECK(syscall) ::aos::CheckSyscall(STRINGIFY(syscall), syscall)
+// Example: const int fd = AOS_PCHECK(open("/tmp/whatever", O_WRONLY))
+#define AOS_PCHECK(syscall) ::aos::CheckSyscall(STRINGIFY(syscall), syscall)
// PELOG(FATAL)s with the result of syscall if it returns anything other than 0.
// This is useful for quickly checking things like many of the pthreads
// functions where it's not very useful to print out the values of any of the
// arguments.
//
-// Example: PRCHECK(munmap(address, length))
-#define PRCHECK(syscall) ::aos::CheckSyscallReturn(STRINGIFY(syscall), syscall)
+// Example: AOS_PRCHECK(munmap(address, length))
+#define AOS_PRCHECK(syscall) \
+ ::aos::CheckSyscallReturn(STRINGIFY(syscall), syscall)
} // namespace aos