1 /* Copyright 2012-present Facebook, Inc. 2 * Licensed under the Apache License, Version 2.0 */ 3 4 // You are encouraged to include "Logging.h" and use those functions rather than 5 // use these. The functions in this file are best suited to low level or early 6 // bootstrapping situations. 7 8 #ifndef WATCHMAN_LOG_H 9 #define WATCHMAN_LOG_H 10 11 // Coupled with enum LogLevel in Logging.h 12 #define W_LOG_OFF 0 13 #define W_LOG_ERR 1 14 #define W_LOG_DBG 2 15 #define W_LOG_FATAL -1 16 17 #include "watchman_preprocessor.h" 18 19 extern int log_level; 20 extern char *log_name; 21 const char *w_set_thread_name(const char *fmt, ...); 22 void w_setup_signal_handlers(void); 23 void w_log(int level, WATCHMAN_FMT_STRING(const char* fmt), ...) 24 WATCHMAN_FMT_ATTR(2, 3); 25 26 #define w_check(e, ...) \ 27 if (!(e)) { \ 28 w_log(W_LOG_ERR, "%s:%u failed assertion `%s'\n", __FILE__, __LINE__, #e); \ 29 w_log(W_LOG_FATAL, __VA_ARGS__); \ 30 } 31 32 // Similar to assert(), but uses W_LOG_FATAL to log the stack trace 33 // before giving up the ghost 34 #ifdef NDEBUG 35 # define w_assert(e, ...) ((void)0) 36 #else 37 #define w_assert(e, ...) w_check(e, __VA_ARGS__) 38 #endif 39 40 #endif 41