mirror of
https://github.com/wassname/ray.git
synced 2026-08-04 13:14:14 +08:00
Logging level (#38)
* Set logging levels in Makefile using -DRAY_COMMON_LOG_LEVEL=level * Lower level of some LOG_ERROR messages, log the name of the table operation on failure * Address rest of Robert's comments * Fix spurious log message
This commit is contained in:
committed by
Robert Nishihara
parent
986ed5c9e8
commit
7babe0d22f
+38
-8
@@ -11,20 +11,49 @@
|
||||
|
||||
#include "utarray.h"
|
||||
|
||||
#ifndef RAY_COMMON_DEBUG
|
||||
#define RAY_COMMON_DEBUG 0
|
||||
#define RAY_COMMON_INFO 1
|
||||
#define RAY_COMMON_WARNING 2
|
||||
#define RAY_COMMON_ERROR 3
|
||||
#define RAY_COMMON_FATAL 4
|
||||
|
||||
/* Default logging level is INFO. */
|
||||
#ifndef RAY_COMMON_LOG_LEVEL
|
||||
#define RAY_COMMON_LOG_LEVEL RAY_COMMON_INFO
|
||||
#endif
|
||||
|
||||
#if (RAY_COMMON_LOG_LEVEL > RAY_COMMON_DEBUG)
|
||||
#define LOG_DEBUG(M, ...)
|
||||
#else
|
||||
#define LOG_DEBUG(M, ...) \
|
||||
fprintf(stderr, "[DEBUG] (%s:%d) " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#define LOG_ERR(M, ...) \
|
||||
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, \
|
||||
errno == 0 ? "None" : strerror(errno), ##__VA_ARGS__)
|
||||
|
||||
#if (RAY_COMMON_LOG_LEVEL > RAY_COMMON_INFO)
|
||||
#define LOG_INFO(M, ...)
|
||||
#else
|
||||
#define LOG_INFO(M, ...) \
|
||||
fprintf(stderr, "[INFO] (%s:%d) " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if (RAY_COMMON_LOG_LEVEL > RAY_COMMON_WARNING)
|
||||
#define LOG_WARN(M, ...)
|
||||
#else
|
||||
#define LOG_WARN(M, ...) \
|
||||
fprintf(stderr, "[WARN] (%s:%d) " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if (RAY_COMMON_LOG_LEVEL > RAY_COMMON_ERROR)
|
||||
#define LOG_ERROR(M, ...)
|
||||
#else
|
||||
#define LOG_ERROR(M, ...) \
|
||||
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, \
|
||||
errno == 0 ? "None" : strerror(errno), ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if (RAY_COMMON_LOG_LEVEL > RAY_COMMON_FATAL)
|
||||
#define LOG_FATAL(M, ...)
|
||||
#else
|
||||
#define LOG_FATAL(M, ...) \
|
||||
do { \
|
||||
fprintf(stderr, "[FATAL] (%s:%d) " M "\n", __FILE__, __LINE__, \
|
||||
@@ -34,10 +63,11 @@
|
||||
backtrace_symbols_fd(buffer, calls, 1); \
|
||||
exit(-1); \
|
||||
} while (0);
|
||||
#endif
|
||||
|
||||
#define CHECKM(COND, M, ...) \
|
||||
if (!(COND)) { \
|
||||
LOG_ERR("Check failure: %s \n" M, #COND, ##__VA_ARGS__); \
|
||||
#define CHECKM(COND, M, ...) \
|
||||
if (!(COND)) { \
|
||||
LOG_FATAL("Check failure: %s \n" M, #COND, ##__VA_ARGS__); \
|
||||
}
|
||||
|
||||
#define CHECK(COND) CHECKM(COND, "")
|
||||
|
||||
Reference in New Issue
Block a user