diff options
author | James Maki <jmaki@multitech.com> | 2010-04-23 11:58:20 -0500 |
---|---|---|
committer | James Maki <jmaki@multitech.com> | 2010-04-23 11:58:20 -0500 |
commit | 14fb44b17123b27e562379f51b75ee889982688d (patch) | |
tree | 3c2344f5c42396ab839638ee12f7c2f66a2656cb /src/log.h | |
download | sms-utils-14fb44b17123b27e562379f51b75ee889982688d.tar.gz sms-utils-14fb44b17123b27e562379f51b75ee889982688d.tar.bz2 sms-utils-14fb44b17123b27e562379f51b75ee889982688d.zip |
initial commit
Diffstat (limited to 'src/log.h')
-rw-r--r-- | src/log.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/log.h b/src/log.h new file mode 100644 index 0000000..d53b795 --- /dev/null +++ b/src/log.h @@ -0,0 +1,47 @@ +#ifndef __LOG_H +#define __LOG_H + +#include "config.h" + +#if CONFIG_USE_SYSLOG +# include <syslog.h> +# define LOG_FACILITY LOG_USER + +# define __log(level, name, format, args...) \ + syslog(LOG_FACILITY | level, "[" name "] %s:%s:%d: " format "\n" , \ + __FILE__ , __func__ , __LINE__ , ## args) +#else +# define __log(level, name, format, args...) \ + fprintf(stderr, "[" name "] %s:%s:%d: " format "\n" , \ + __FILE__ , __func__ , __LINE__ , ## args) +#endif + +#define log_emerg(format, args...) __log(LOG_EMERG, "EMERG", format , ## args) +#define log_alert(format, args...) __log(LOG_ALERT, "ALERT", format , ## args) +#define log_crit(format, args...) __log(LOG_CRIT, "CRIT", format , ## args) +#define log_error(format, args...) __log(LOG_ERR, "ERROR", format , ## args) +#define log_warning(format, args...) __log(LOG_WARNING, "WARNING", format , ## args) +#define log_notice(format, args...) __log(LOG_NOTICE, "NOTICE", format , ## args) +#define log_info(format, args...) __log(LOG_INFO, "INFO", format , ## args) +#if DEBUG +# define log_debug(format, args...) __log(LOG_DEBUG, "DEBUG", format , ## args) +#else +# define log_debug(format, args...) do {} while (0) +#endif + +#if DEBUG +# define debug_buffer(msg, buf, len) \ +do { \ + __log(LOG_DEBUG, "DEBUG", msg " \"%.*J\"", len, buf); \ +} while (0) +#else +# define debug_buffer(_msg, _buf, _len) do { } while (0) +#endif + +#define BUG(format, args...) \ +do { \ + log_emerg("BUG: " format , ## args); \ + exit(124); \ +} while (0) + +#endif /* ~__LOG_H */ |