spf_log.h

Go to the documentation of this file.
00001 /* 
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of either:
00004  * 
00005  *   a) The GNU Lesser General Public License as published by the Free
00006  *      Software Foundation; either version 2.1, or (at your option) any
00007  *      later version,
00008  * 
00009  *   OR
00010  * 
00011  *   b) The two-clause BSD license.
00012  *
00013  * These licenses can be found with the distribution in the file LICENSES
00014  */
00015 
00016 
00017 
00018 #ifndef INC_SPF_LOG
00019 #define INC_SPF_LOG
00020 
00037 #include <stdarg.h>
00038 
00039 
00040 #define SPF_error(errmsg) SPF_errorx( __FILE__, __LINE__, "%s", errmsg )
00041 void SPF_errorx( const char *file, int line, const char *format, ... ) __attribute__ ((noreturn)) __attribute__ ((format (printf, 3, 4)));
00042 void SPF_errorx2( const char *format, ... );
00043 void SPF_errorv( const char *file, int line, const char *format, va_list ap ) __attribute__ ((noreturn)) __attribute__ ((format (printf, 3, 0)));
00044 
00045 #define SPF_warning(errmsg) SPF_warningx( __FILE__, __LINE__, "%s", errmsg )
00046 void SPF_warningx( const char *file, int line, const char *format, ... ) __attribute__ ((format (printf, 3, 4)));
00047 void SPF_warningx2( const char *format, ... );
00048 void SPF_warningv( const char *file, int line, const char *format, va_list ap ) __attribute__ ((format (printf, 3, 0)));
00049 
00050 #define SPF_info(errmsg) SPF_infox( __FILE__, __LINE__, "%s", errmsg )
00051 void SPF_infox( const char *file, int line, const char *format, ... ) __attribute__ ((format (printf, 3, 4)));
00052 void SPF_infox2( const char *format, ... );
00053 void SPF_infov( const char *file, int line, const char *format, va_list ap ) __attribute__ ((format (printf, 3, 0)));
00054 
00055 #define SPF_debug(errmsg) SPF_debugx( __FILE__, __LINE__, "%s", errmsg )
00056 void SPF_debugx( const char *file, int line, const char *format, ... ) __attribute__ ((format (printf, 3, 4)));
00057 void SPF_debugx2( const char *format, ... );
00058 void SPF_debugv( const char *file, int line, const char *format, va_list ap ) __attribute__ ((format (printf, 3, 0)));
00059 
00060 
00061 #if defined( __STDC_VERSION__ ) && __STDC_VERSION__ >= 199901L
00062 
00063 #define SPF_errorf(format, ... ) SPF_errorx( __FILE__, __LINE__, format, __VA_ARGS__ )
00064 #define SPF_warningf(format, ... ) SPF_warningx( __FILE__, __LINE__, format, __VA_ARGS__ )
00065 #define SPF_infof(format, ... ) SPF_infox( __FILE__, __LINE__, format, __VA_ARGS__ )
00066 #define SPF_debugf(format, ... ) SPF_debugx( __FILE__, __LINE__, format, __VA_ARGS__ )
00067 
00068 #elif defined( __GNUC__ )
00069 
00070 #define SPF_errorf(format... ) SPF_errorx( __FILE__, __LINE__, format )
00071 #define SPF_warningf(format... ) SPF_warningx( __FILE__, __LINE__, format )
00072 #define SPF_infof(format... ) SPF_infox( __FILE__, __LINE__, format )
00073 #define SPF_debugf(format... ) SPF_debugx( __FILE__, __LINE__, format )
00074 
00075 #else
00076 
00077 #define SPF_errorf      SPF_errorx2
00078 #define SPF_warningf    SPF_warningx2
00079 #define SPF_infof       SPF_infox2
00080 #define SPF_debugf      SPF_debugx2
00081 
00082 #endif
00083 
00084 
00085 /* These message handler routines print to stderr or stdout, as appropriate. */
00086 
00087 void SPF_error_stdio( const char *file, int line, const char *errmsg ) __attribute__ ((noreturn));
00088 void SPF_warning_stdio( const char *file, int line, const char *errmsg );
00089 void SPF_info_stdio( const char *file __attribute__ ((unused)), int line __attribute__ ((unused)), const char *errmsg );
00090 void SPF_debug_stdio( const char *file, int line, const char *errmsg );
00091 
00092 
00093 /* These message handler routines send messages to syslog */
00094 
00095 void SPF_error_syslog( const char *file, int line, const char *errmsg ) __attribute__ ((noreturn));
00096 void SPF_warning_syslog( const char *file, int line, const char *errmsg );
00097 void SPF_info_syslog( const char *file __attribute__ ((unused)), int line __attribute__ ((unused)), const char *errmsg );
00098 void SPF_debug_syslog( const char *file, int line, const char *errmsg );
00099 
00100 /* FYI only -- can't be changed without recompiling the library */
00101 #define SPF_DEFAULT_ERROR_HANDLER       SPF_error_stdio
00102 #define SPF_DEFAULT_WARNING_HANDLER     SPF_warning_stdio
00103 #define SPF_DEFAULT_INFO_HANDLER        SPF_info_stdio
00104 #define SPF_DEFAULT_DEBUG_HANDLER       SPF_debug_stdio
00105 
00106 
00107 /*
00108  * You can assign these global function pointers to whatever routines
00109  * you want to handle the various types of messages.  Setting them to NULL
00110  * will cause the messages to be ignored.
00111  */
00112  
00113 extern void (*SPF_error_handler)( const char *, int, const char * ) __attribute__ ((noreturn));
00114 extern void (*SPF_warning_handler)( const char *, int, const char * );
00115 extern void (*SPF_info_handler)( const char *, int, const char * );
00116 extern void (*SPF_debug_handler)( const char *, int, const char * );
00117 
00118 #define SPF_ASSERT_NOTNULL(x) \
00119         do { if ((x) == NULL) SPF_error(#x " is NULL"); } while(0)
00120 
00121 
00122 
00123 
00124 #endif

Generated on Tue Nov 4 13:27:38 2008 for libspf2 by  doxygen 1.5.4