/* log.h — leveled logging. * * Phase 1: a straightforward thread-safe stderr logger (one writev per record, * so lines never interleave). The data path does not log per-message; this is * for lifecycle, errors, and stats. A lock-free per-thread ring drain is a * later optimization behind the same macros, so call sites never change. */ #ifndef NAUT_LOG_H #define NAUT_LOG_H #include "naut/common.h" typedef enum { NAUT_LOG_ERROR = 0, NAUT_LOG_WARN, NAUT_LOG_INFO, NAUT_LOG_DEBUG, NAUT_LOG_TRACE, } naut_log_level; void naut_log_set_level(naut_log_level lvl); naut_log_level naut_log_get_level(void); void naut_log_emit(naut_log_level lvl, const char *file, int line, const char *fmt, ...) NAUT_PRINTF(4, 5); #define NAUT_LOG(lvl, ...) \ do { if ((lvl) <= naut_log_get_level()) \ naut_log_emit((lvl), __FILE__, __LINE__, __VA_ARGS__); } while (0) #define NAUT_ERROR(...) NAUT_LOG(NAUT_LOG_ERROR, __VA_ARGS__) #define NAUT_WARN(...) NAUT_LOG(NAUT_LOG_WARN, __VA_ARGS__) #define NAUT_INFO(...) NAUT_LOG(NAUT_LOG_INFO, __VA_ARGS__) #define NAUT_DEBUG(...) NAUT_LOG(NAUT_LOG_DEBUG, __VA_ARGS__) #define NAUT_TRACE(...) NAUT_LOG(NAUT_LOG_TRACE, __VA_ARGS__) /* Fatal: log and abort(). Use only for unrecoverable invariant violations. */ NAUT_NORETURN void naut_panic(const char *file, int line, const char *fmt, ...) NAUT_PRINTF(3, 4); #define NAUT_PANIC(...) naut_panic(__FILE__, __LINE__, __VA_ARGS__) #define NAUT_ASSERT(cond) \ do { if (NAUT_UNLIKELY(!(cond))) NAUT_PANIC("assertion failed: %s", #cond); } while (0) #endif /* NAUT_LOG_H */