From d64294639375cd5758cd7abe090348d62e5d9ca7 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 7 Dec 2012 14:01:16 +0100 Subject: Completely new interface. --- debug.h | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 96 insertions(+), 3 deletions(-) (limited to 'debug.h') diff --git a/debug.h b/debug.h index 0c5e3a5..1241f67 100644 --- a/debug.h +++ b/debug.h @@ -28,10 +28,103 @@ #ifndef __DEBUG_MODULE_DEBUG_H__ #define __DEBUG_MODULE_DEBUG_H__ -#include +enum DBG_FLAG { + // Features +#ifdef WITH_DBG_THREAD + DBG_FLAG_USE_THREAD = 0x00000001, +#endif +#ifdef WITH_DBG_MUTEX + DBG_FLAG_USE_MUTEX = 0x00000002, +#endif +#ifdef WITH_DBG_FILTER + DBG_FLAG_USE_FILTER = 0x00000004, +#endif -void debug_init(FILE *fp); -void debug_parse(const char *fmt); + // Outputs + DBG_FLAG_OUTPUT_TO_STDOUT = 0x00010000, + DBG_FLAG_OUTPUT_TO_STDERR = 0x00020000, + DBG_FLAG_OUTPUT_TO_FD = 0x00040000, + DBG_FLAG_OUTPUT_TO_FILE = 0x00080000, +#ifdef WITH_DBG_SYSLOG + DBG_FLAG_OUTPUT_TO_SYSLOG = 0x000f0000, +#endif + + // Default value of flags + DBG_FLAG_DEFAULT = DBG_FLAG_OUTPUT_TO_STDOUT, // Output to stdout +}; + +enum DBG_OPTION { + /** + * No more options / last option. This is used + * to terminate the VARARGs list. + */ + DBG_OPTION_END, + + /** + * const char* argument containing a filename which will be used for log + * output. To be used with the DBG_FLAG_OUTPUT_TO_FILE flag. + */ + DBG_OPTION_FILENAME, + + /** + * Integer argument describing a file descriptor which will be used for log + * output. To be used with the DBG_FLAG_OUTPUT_TO_FD flag. + */ + DBG_OPTION_FD, + + /** + * Host and port to use when logging on an external server. + * Host is a const char* argument, port is an integer. + * To be used with the DBG_FLAG_USE_SYSLOG flag. + * Linux: If DBG_OPTION_SYSLOG_HOST is not supplied, the local syslog will be + * used. + * Windows: If DBG_OPTION_SYSLOG_HOST is not supplied an error will be + * returned by debug_init. + * If DBG_OPTION_SYSLOG_PORT is not supplied, the default syslogd port will + * be used (port 514). + */ +#ifdef WITH_DBG_SYSLOG + DBG_OPTION_SYSLOG_HOST, + DBG_OPTION_SYSLOG_PORT, +#endif + + /** + * + */ +}; + +typedef enum { + DBG_STATUS_OK = 0, + DBG_STATUS_UNKNOWN_OPTION, + DBG_STATUS_ERROR, +} dbg_status_t; + +/** + * @param flags combination of DBG_FLAG values + * @param ... list of options (type-value pairs, + * terminated with DBG_OPTION_END). + * @return 0 on success, 1 on error. + */ +dbg_status_t dbg_init(unsigned int flags, ...); +void dbg_close(); + +/** + * Example of usage (use mutex protected calls, send output to file): + * + * dbg_status_t status; + * status = debug_init(DBG_FLAG_OUTPUT_TO_FILE | DBG_FLAG_USE_MUTEX, + * DBG_OPTION_FILENAME, "/tmp/my.log", + DBG_OPTION_END); + * if(status != DBG_STATUS_OK) exit(1); + * INFO(example, "We are up and running\n"); + * dbg_close(); + */ + +/** + * Example of usage (simply outputs to stdout): + * + * INFO(example, "We are up and running\n"); + */ enum __debug_class { -- cgit v1.2.3