libspf2 1.2.11
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 )
41void SPF_errorx( const char *file, int line, const char *format, ... ) __attribute__ ((noreturn)) __attribute__ ((format (printf, 3, 4)));
42void SPF_errorx2( const char *format, ... );
43void 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 )
46void SPF_warningx( const char *file, int line, const char *format, ... ) __attribute__ ((format (printf, 3, 4)));
47void SPF_warningx2( const char *format, ... );
48void 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 )
51void SPF_infox( const char *file, int line, const char *format, ... ) __attribute__ ((format (printf, 3, 4)));
52void SPF_infox2( const char *format, ... );
53void 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 )
56void SPF_debugx( const char *file, int line, const char *format, ... ) __attribute__ ((format (printf, 3, 4)));
57void SPF_debugx2( const char *format, ... );
58void 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
87void SPF_error_stdio( const char *file, int line, const char *errmsg ) __attribute__ ((noreturn));
88void SPF_warning_stdio( const char *file, int line, const char *errmsg );
89void SPF_info_stdio( const char *file __attribute__ ((unused)), int line __attribute__ ((unused)), const char *errmsg );
90void SPF_debug_stdio( const char *file, int line, const char *errmsg );
91
92
93/* These message handler routines send messages to syslog */
94
95void SPF_error_syslog( const char *file, int line, const char *errmsg ) __attribute__ ((noreturn));
96void SPF_warning_syslog( const char *file, int line, const char *errmsg );
97void SPF_info_syslog( const char *file __attribute__ ((unused)), int line __attribute__ ((unused)), const char *errmsg );
98void 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
113extern void (*SPF_error_handler)( const char *, int, const char * ) __attribute__ ((noreturn));
114extern void (*SPF_warning_handler)( const char *, int, const char * );
115extern void (*SPF_info_handler)( const char *, int, const char * );
116extern 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
#define const
#define __attribute__(x)
Definition spf.h:17
void SPF_debug_syslog(const char *file, int line, const char *errmsg)
void(* SPF_warning_handler)(const char *, int, const char *)
void SPF_error_stdio(const char *file, int line, const char *errmsg) __attribute__((noreturn))
void SPF_infox(const char *file, int line, const char *format,...) __attribute__((format(printf
void SPF_warning_stdio(const char *file, int line, const char *errmsg)
void SPF_infov(const char *file, int line, const char *format, va_list ap) __attribute__((format(printf
void SPF_debugx(const char *file, int line, const char *format,...) __attribute__((format(printf
void SPF_warning_syslog(const char *file, int line, const char *errmsg)
void void SPF_infox2(const char *format,...)
Definition spf_log.c:185
void SPF_warningx(const char *file, int line, const char *format,...) __attribute__((format(printf
void(* SPF_debug_handler)(const char *, int, const char *)
void SPF_info_syslog(const char *file __attribute__((unused)), int line __attribute__((unused)), const char *errmsg)
void void SPF_debugx2(const char *format,...)
Definition spf_log.c:194
void SPF_debug_stdio(const char *file, int line, const char *errmsg)
void SPF_errorv(const char *file, int line, const char *format, va_list ap) __attribute__((noreturn)) __attribute__((format(printf
void SPF_info_stdio(const char *file __attribute__((unused)), int line __attribute__((unused)), const char *errmsg)
void SPF_warningv(const char *file, int line, const char *format, va_list ap) __attribute__((format(printf
void SPF_debugv(const char *file, int line, const char *format, va_list ap) __attribute__((format(printf
void SPF_errorx(const char *file, int line, const char *format,...) __attribute__((noreturn)) __attribute__((format(printf
void SPF_error_syslog(const char *file, int line, const char *errmsg) __attribute__((noreturn))
void(* SPF_info_handler)(const char *, int, const char *)
void(* SPF_error_handler)(const char *, int, const char *) __attribute__((noreturn))
void void SPF_warningx2(const char *format,...)
Definition spf_log.c:176
void void SPF_errorx2(const char *format,...)
Definition spf_log.c:167