1 /* 2 3 ---------------------------------------------------- 4 httpry - HTTP logging and information retrieval tool 5 ---------------------------------------------------- 6 7 Copyright (c) 2005-2014 Jason Bittel <jason.bittel@gmail.com> 8 9 */ 10 11 #ifndef _HAVE_ERROR_H 12 #define _HAVE_ERROR_H 13 14 #include <signal.h> 15 #include <syslog.h> 16 #include "config.h" 17 18 extern int quiet_mode; 19 extern int use_syslog; 20 21 /* Macros for logging/displaying status messages */ 22 #define PRINT(x...) { if (!quiet_mode) { fprintf(stderr, x); fprintf(stderr, "\n"); } } 23 #define WARN(x...) { fprintf(stderr, "Warning: " x); fprintf(stderr, "\n"); } 24 #define LOG(x...) { if (use_syslog) { openlog(PROG_NAME, LOG_PID, LOG_DAEMON); syslog(LOG_ERR, x); closelog(); } } 25 #define DIE(x...) { fprintf(stderr, "Error: " x); fprintf(stderr, "\n"); raise(SIGINT); } 26 #define LOG_PRINT(x...) { LOG(x); PRINT(x); } 27 #define LOG_WARN(x...) { LOG(x); WARN(x); } 28 #define LOG_DIE(x...) { LOG(x); DIE(x); } 29 30 /* Assert macro for testing and debugging; use 'make debug' 31 to compile the program with debugging features enabled */ 32 #ifdef DEBUG 33 #define ASSERT(x) \ 34 if (!(x)) { \ 35 fflush(NULL); \ 36 fprintf(stderr, "\nAssertion failed: %s, line %d\n", \ 37 __FILE__, __LINE__); \ 38 fflush(stderr); \ 39 exit(EXIT_FAILURE); \ 40 } 41 #endif 42 43 #endif /* ! _HAVE_ERROR_H */ 44