libspf2  1.2.10
spf_log.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of either:
4  *
5  * a) The GNU Lesser General Public License as published by the Free
6  * Software Foundation; either version 2.1, or (at your option) any
7  * later version,
8  *
9  * OR
10  *
11  * b) The two-clause BSD license.
12  *
13  * These licenses can be found with the distribution in the file LICENSES
14  */
15 
16 
17 
18 #ifndef INC_SPF_LOG
19 #define INC_SPF_LOG
20 
37 #include <stdarg.h>
38 
39 
40 #define SPF_error(errmsg) SPF_errorx( __FILE__, __LINE__, "%s", errmsg )
41 void SPF_errorx( const char *file, int line, const char *format, ... ) __attribute__ ((noreturn)) __attribute__ ((format (printf, 3, 4)));
42 void SPF_errorx2( const char *format, ... );
43 void SPF_errorv( const char *file, int line, const char *format, va_list ap ) __attribute__ ((noreturn)) __attribute__ ((format (printf, 3, 0)));
44 
45 #define SPF_warning(errmsg) SPF_warningx( __FILE__, __LINE__, "%s", errmsg )
46 void SPF_warningx( const char *file, int line, const char *format, ... ) __attribute__ ((format (printf, 3, 4)));
47 void SPF_warningx2( const char *format, ... );
48 void SPF_warningv( const char *file, int line, const char *format, va_list ap ) __attribute__ ((format (printf, 3, 0)));
49 
50 #define SPF_info(errmsg) SPF_infox( __FILE__, __LINE__, "%s", errmsg )
51 void SPF_infox( const char *file, int line, const char *format, ... ) __attribute__ ((format (printf, 3, 4)));
52 void SPF_infox2( const char *format, ... );
53 void SPF_infov( const char *file, int line, const char *format, va_list ap ) __attribute__ ((format (printf, 3, 0)));
54 
55 #define SPF_debug(errmsg) SPF_debugx( __FILE__, __LINE__, "%s", errmsg )
56 void SPF_debugx( const char *file, int line, const char *format, ... ) __attribute__ ((format (printf, 3, 4)));
57 void SPF_debugx2( const char *format, ... );
58 void SPF_debugv( const char *file, int line, const char *format, va_list ap ) __attribute__ ((format (printf, 3, 0)));
59 
60 
61 #if defined( __STDC_VERSION__ ) && __STDC_VERSION__ >= 199901L
62 
63 #define SPF_errorf(format, ... ) SPF_errorx( __FILE__, __LINE__, format, ##__VA_ARGS__ )
64 #define SPF_warningf(format, ... ) SPF_warningx( __FILE__, __LINE__, format, ##__VA_ARGS__ )
65 #define SPF_infof(format, ... ) SPF_infox( __FILE__, __LINE__, format, ##__VA_ARGS__ )
66 #define SPF_debugf(format, ... ) SPF_debugx( __FILE__, __LINE__, format, ##__VA_ARGS__ )
67 
68 #elif defined( __GNUC__ )
69 
70 #define SPF_errorf(format... ) SPF_errorx( __FILE__, __LINE__, format )
71 #define SPF_warningf(format... ) SPF_warningx( __FILE__, __LINE__, format )
72 #define SPF_infof(format... ) SPF_infox( __FILE__, __LINE__, format )
73 #define SPF_debugf(format... ) SPF_debugx( __FILE__, __LINE__, format )
74 
75 #else
76 
77 #define SPF_errorf SPF_errorx2
78 #define SPF_warningf SPF_warningx2
79 #define SPF_infof SPF_infox2
80 #define SPF_debugf SPF_debugx2
81 
82 #endif
83 
84 
85 /* These message handler routines print to stderr or stdout, as appropriate. */
86 
87 void SPF_error_stdio( const char *file, int line, const char *errmsg ) __attribute__ ((noreturn));
88 void SPF_warning_stdio( const char *file, int line, const char *errmsg );
89 void SPF_info_stdio( const char *file __attribute__ ((unused)), int line __attribute__ ((unused)), const char *errmsg );
90 void SPF_debug_stdio( const char *file, int line, const char *errmsg );
91 
92 
93 /* These message handler routines send messages to syslog */
94 
95 void SPF_error_syslog( const char *file, int line, const char *errmsg ) __attribute__ ((noreturn));
96 void SPF_warning_syslog( const char *file, int line, const char *errmsg );
97 void SPF_info_syslog( const char *file __attribute__ ((unused)), int line __attribute__ ((unused)), const char *errmsg );
98 void SPF_debug_syslog( const char *file, int line, const char *errmsg );
99 
100 /* FYI only -- can't be changed without recompiling the library */
101 #define SPF_DEFAULT_ERROR_HANDLER SPF_error_stdio
102 #define SPF_DEFAULT_WARNING_HANDLER SPF_warning_stdio
103 #define SPF_DEFAULT_INFO_HANDLER SPF_info_stdio
104 #define SPF_DEFAULT_DEBUG_HANDLER SPF_debug_stdio
105 
106 
107 /*
108  * You can assign these global function pointers to whatever routines
109  * you want to handle the various types of messages. Setting them to NULL
110  * will cause the messages to be ignored.
111  */
112 
113 extern void (*SPF_error_handler)( const char *, int, const char * ) __attribute__ ((noreturn));
114 extern void (*SPF_warning_handler)( const char *, int, const char * );
115 extern void (*SPF_info_handler)( const char *, int, const char * );
116 extern void (*SPF_debug_handler)( const char *, int, const char * );
117 
118 #define SPF_ASSERT_NOTNULL(x) \
119  do { if ((x) == NULL) SPF_error(#x " is NULL"); } while(0)
120 
121 
122 
123 
124 #endif
SPF_errorv
void SPF_errorv(const char *file, int line, const char *format, va_list ap) __attribute__((noreturn)) __attribute__((format(printf
SPF_warningv
void SPF_warningv(const char *file, int line, const char *format, va_list ap) __attribute__((format(printf
SPF_error_handler
void(* SPF_error_handler)(const char *, int, const char *) __attribute__((noreturn))
SPF_info_handler
void(* SPF_info_handler)(const char *, int, const char *)
SPF_errorx
void SPF_errorx(const char *file, int line, const char *format,...) __attribute__((noreturn)) __attribute__((format(printf
__attribute__
#define __attribute__(x)
Definition: spf.h:17
SPF_infox
void SPF_infox(const char *file, int line, const char *format,...) __attribute__((format(printf
SPF_info_syslog
void SPF_info_syslog(const char *file __attribute__((unused)), int line __attribute__((unused)), const char *errmsg)
SPF_debug_handler
void(* SPF_debug_handler)(const char *, int, const char *)
SPF_warning_stdio
void SPF_warning_stdio(const char *file, int line, const char *errmsg)
Definition: spf_log_stdio.c:48
SPF_error_syslog
void SPF_error_syslog(const char *file, int line, const char *errmsg) __attribute__((noreturn))
SPF_infov
void SPF_infov(const char *file, int line, const char *format, va_list ap) __attribute__((format(printf
SPF_warning_handler
void(* SPF_warning_handler)(const char *, int, const char *)
SPF_info_stdio
void SPF_info_stdio(const char *file __attribute__((unused)), int line __attribute__((unused)), const char *errmsg)
Definition: spf_log_stdio.c:61
SPF_error_stdio
void SPF_error_stdio(const char *file, int line, const char *errmsg) __attribute__((noreturn))
Definition: spf_log_stdio.c:34
SPF_debugv
void SPF_debugv(const char *file, int line, const char *format, va_list ap) __attribute__((format(printf
SPF_warning_syslog
void SPF_warning_syslog(const char *file, int line, const char *errmsg)
SPF_debugx
void SPF_debugx(const char *file, int line, const char *format,...) __attribute__((format(printf
SPF_debug_stdio
void SPF_debug_stdio(const char *file, int line, const char *errmsg)
Definition: spf_log_stdio.c:67
SPF_warningx
void SPF_warningx(const char *file, int line, const char *format,...) __attribute__((format(printf
SPF_warningx2
void void SPF_warningx2(const char *format,...)
Definition: spf_log.c:176
SPF_errorx2
void void SPF_errorx2(const char *format,...)
Definition: spf_log.c:167
SPF_infox2
void void SPF_infox2(const char *format,...)
Definition: spf_log.c:185
SPF_debugx2
void void SPF_debugx2(const char *format,...)
Definition: spf_log.c:194
SPF_debug_syslog
void SPF_debug_syslog(const char *file, int line, const char *errmsg)
const
#define const
Definition: getopt_long_only.c:38