/* logger.c : PUBLIC DOMAIN - Jon Mayo - 2006 */ #ifndef LOGGER_H #define LOGGER_H #include /* log filters */ #define LOG_BIT_INFO 1 #define LOG_BIT_ERROR 2 #define LOG_BIT_WARNING 4 #define LOG_BIT_VERBOSE 8 #define LOG_BIT_DEBUG 16 #define LOG_BIT_LUA 32 #define LOG_BIT_ALL 1023 /* low 10 bits are for logging filters */ /* the following are not a logging modes, but a config options */ #define LOG_BIT_TIMESTAMP 16384 /* prepend timestamps */ #define LOG_BIT_LOCALTIME 32768 /* use localtime instead of UTC */ #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L #define LOG_INFO(...) log_message(LOG_BIT_INFO, "INFO", ## __VA_ARGS__) #define LOG_WARNING(...) log_imessage(LOG_BIT_WARNING, "WARNING", __FILE__, __func__, __LINE__, ## __VA_ARGS__) #define LOG_DEBUG(...) log_imessage(LOG_BIT_DEBUG, "DEBUG", __FILE__, __func__, __LINE__, ## __VA_ARGS__) #define LOG_ERROR(...) log_imessage(LOG_BIT_ERROR, "ERROR", __FILE__, __func__, __LINE__, ## __VA_ARGS__) #define LOG_VERBOSE(...) log_imessage(LOG_BIT_VERBOSE, "VERBOSE", __FILE__, __func__, __LINE__, ## __VA_ARGS__) #define LOG_ERRNO(reason) log_message(LOG_BIT_ERROR, "ERROR", "%s:%s\n", reason, strerror(errno)); #elif defined __GNUC__ && __GNUC__ >= 2 #warning C99 not detected, using GNU extensions #define LOG_INFO(x...) log_message(LOG_BIT_INFO, "INFO", ## x) #define LOG_WARNING(x...) log_imessage(LOG_BIT_WARNING, "WARNING", __FILE__, __FUNCTION__, __LINE__, ## x) #define LOG_DEBUG(x...) log_imessage(LOG_BIT_DEBUG, "DEBUG", __FILE__, __FUNCTION__, __LINE__, ## x) #define LOG_ERROR(x...) log_imessage(LOG_BIT_ERROR, "ERROR", __FILE__, __FUNCTION__, __LINE__, ## x) #define LOG_VERBOSE(x...) log_imessage(LOG_BIT_VERBOSE, "VERBOSE", __FILE__, __FUNCTION__, __LINE__, ## x) #define LOG_ERRNO(reason) log_message(LOG_BIT_ERROR, "ERROR", "%s:%s\n", reason, strerror(errno)); #else #error A C99 compliant compiler is required for this module. Please put your compiler in C99 mode #endif void log_vimessage(unsigned mode, const char *level_name, const char *filename, const char *func, unsigned line, const char *fmt, va_list ap); void log_vmessage(unsigned mode, const char *level_name, const char *fmt, va_list ap); void log_imessage(unsigned mode, const char *level_name, const char *filename, const char *func, unsigned line, const char *fmt, ...); void log_message(unsigned mode, const char *level_name, const char *fmt, ...); void log_timestamp(unsigned mode, const char *level, const char *message); int log_init(const char *file, unsigned log_bits); void log_enable(unsigned bits); void log_disable(unsigned bits); void log_shutdown(void); #endif