Main Page | Data Structures | Directories | File List | Data Fields | Globals

logerr.h

Go to the documentation of this file.
00001 
00024 /* This file is part of tclSadie.
00025 
00026    tclSadie is free software; you can redistribute it and/or modify it
00027    under the terms of the GNU General Public License as published by
00028    the Free Software Foundation; either version 2 of the License, or
00029    (at your option) any later version.
00030 
00031    tclSadie is distributed in the hope that it will be useful, but
00032    WITHOUT ANY WARRANTY; without even the implied warranty of
00033    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00034    General Public License for more details.
00035 
00036    You should have received a copy of the GNU General Public License
00037    along with tclSadie; if not, write to the Free Software Foundation,
00038    Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.  */
00039 
00040 #ifndef LOGERR_H
00041 
00042 #define LOGERR_H 1
00043 #include <stdarg.h>
00044 #include "project_utilities.h"
00045 
00046 BEGIN_C_DECLARATIONS
00047 
00049 typedef enum
00050   {
00051     LOGERR_EMERG   = 0, 
00052     LOGERR_ALERT   = 1, 
00053     LOGERR_CRIT    = 2, 
00054     LOGERR_ERR     = 3, 
00055     LOGERR_WARNING = 4, 
00056     LOGERR_NOTICE  = 5, 
00057     LOGERR_INFO    = 6, 
00058     LOGERR_DEBUG   = 7  
00059   } logerr_priority;
00060 
00061 #ifndef LOGERR_THRESHOLD_REPORT
00062 
00063 #define LOGERR_THRESHOLD_REPORT LOGERR_DEBUG
00064 #endif
00065 
00066 #ifndef LOGERR_THRESHOLD_ABORT
00067 
00068 #define LOGERR_THRESHOLD_ABORT LOGERR_ERR
00069 #endif
00070 
00072 typedef void (*logerr_message_poster_t) (int priority, const char * title,
00073                                          const char * message);
00075 typedef void (*logerr_perror_poster_t) (int priority, const char * title,
00076                                         const char * message, const char * syserr);
00077 
00078 void logerr_vdispatch (int priority, const char * title,
00079                        const char * fmt, va_list ap);
00080 void logerr_dispatch (int priority, const char * title,
00081                       const char * fmt, ...);
00082 
00083 void logerr_vperror (int priority, int errnum, const char * title,
00084                      const char * fmt, va_list ap);
00085 
00086 void logerr_perror (int priority, int errnum, const char * title,
00087                     const char * fmt, ...);
00088 
00089 #if HAVE_C99_VARARGS
00090 
00091 #define logerr(priority, title, ...) do { \
00092     if (priority <= LOGERR_THRESHOLD_REPORT) \
00093       logerr_dispatch (priority, title, __VA_ARGS__); \
00094   } while (0)
00095 
00096 #define logerrno(priority, errnum, title, ...) do { \
00097     if (priority <= LOGERR_THRESHOLD_REPORT) \
00098       logerr_perror (priority, errnum, title, __VA_ARGS__); \
00099   } while (0)
00100 
00101 #define logerr_emerg(title, ...) do { \
00102     if (LOGERR_EMERG <= LOGERR_THRESHOLD_REPORT) \
00103       logerr_dispatch (LOGERR_EMERG, title, __VA_ARGS__); \
00104   } while (0)
00105 
00106 #define logerr_alert(title, ...) do { \
00107     if (LOGERR_ALERT <= LOGERR_THRESHOLD_REPORT) \
00108       logerr_dispatch (LOGERR_ALERT, title, __VA_ARGS__); \
00109   } while (0)
00110 
00111 #define logerr_crit(title, ...) do { \
00112     if (LOGERR_CRIT <= LOGERR_THRESHOLD_REPORT) \
00113       logerr_dispatch (LOGERR_CRIT, title, __VA_ARGS__); \
00114   } while (0)
00115 
00116 #define logerr_err(title, ...) do { \
00117     if (LOGERR_ERR <= LOGERR_THRESHOLD_REPORT) \
00118       logerr_dispatch (LOGERR_ERR, title, __VA_ARGS__); \
00119   } while (0)
00120 
00121 #define logerr_warning(title, ...) do { \
00122     if (LOGERR_WARNING <= LOGERR_THRESHOLD_REPORT) \
00123       logerr_dispatch (LOGERR_WARNING, title, __VA_ARGS__); \
00124   } while (0)
00125 
00126 #define logerr_notice(title, ...) do { \
00127     if (LOGERR_NOTICE <= LOGERR_THRESHOLD_REPORT) \
00128       logerr_dispatch (LOGERR_NOTICE, title, __VA_ARGS__); \
00129   } while (0)
00130 
00131 #define logerr_info(title, ...) do { \
00132     if (LOGERR_INFO <= LOGERR_THRESHOLD_REPORT) \
00133       logerr_dispatch (LOGERR_INFO, title, __VA_ARGS__); \
00134   } while (0)
00135 
00136 #define logerr_debug(title, ...) do { \
00137     if (LOGERR_DEBUG <= LOGERR_THRESHOLD_REPORT) \
00138       logerr_dispatch (LOGERR_DEBUG, title, __VA_ARGS__); \
00139   } while (0)
00140 #elif HAVE_OLDGCC_VARARGS
00141 
00142 #define logerr(priority, title, fmt...) do { \
00143     if (priority <= LOGERR_THRESHOLD_REPORT) \
00144       logerr_dispatch (priority, title, fmt); \
00145   } while (0)
00146 
00147 #define logerrno(priority, errnum, title, fmt...) do { \
00148     if (priority <= LOGERR_THRESHOLD_REPORT) \
00149       logerr_perror (priority, errnum, title, fmt); \
00150   } while (0)
00151 
00152 #define logerr_emerg(title, fmt...) do { \
00153     if (LOGERR_EMERG <= LOGERR_THRESHOLD_REPORT) \
00154       logerr_dispatch (LOGERR_EMERG, title, fmt); \
00155   } while (0)
00156 
00157 #define logerr_alert(title, fmt...) do { \
00158     if (LOGERR_ALERT <= LOGERR_THRESHOLD_REPORT) \
00159       logerr_dispatch (LOGERR_ALERT, title, fmt); \
00160   } while (0)
00161 
00162 #define logerr_crit(title, fmt...) do { \
00163     if (LOGERR_CRIT <= LOGERR_THRESHOLD_REPORT) \
00164       logerr_dispatch (LOGERR_CRIT, title, fmt); \
00165   } while (0)
00166 
00167 #define logerr_err(title, fmt...) do { \
00168     if (LOGERR_ERR <= LOGERR_THRESHOLD_REPORT) \
00169       logerr_dispatch (LOGERR_ERR, title, fmt); \
00170   } while (0)
00171 
00172 #define logerr_warning(title, fmt...) do { \
00173     if (LOGERR_WARNING <= LOGERR_THRESHOLD_REPORT) \
00174       logerr_dispatch (LOGERR_WARNING, title, fmt); \
00175   } while (0)
00176 
00177 #define logerr_notice(title, fmt...) do { \
00178     if (LOGERR_NOTICE <= LOGERR_THRESHOLD_REPORT) \
00179       logerr_dispatch (LOGERR_NOTICE, title, fmt); \
00180   } while (0)
00181 
00182 #define logerr_info(title, fmt...) do { \
00183     if (LOGERR_INFO <= LOGERR_THRESHOLD_REPORT) \
00184       logerr_dispatch (LOGERR_INFO, title, fmt); \
00185   } while (0)
00186 
00187 #define logerr_debug(title, fmt...) do { \
00188     if (LOGERR_DEBUG <= LOGERR_THRESHOLD_REPORT) \
00189       logerr_dispatch (LOGERR_DEBUG, title, fmt); \
00190   } while (0)
00191 #else /* we can't use varadic preprocessor macros */
00192 
00202 static void
00203 logerr (int priority, const char * title, const char * fmt, ...)
00204 {
00205   va_list ap;
00206 
00207   if (priority <= LOGERR_THRESHOLD_REPORT)
00208     {
00209       va_start (ap, fmt);
00210       logerr_vdispatch (priority, title, fmt, ap);
00211       va_end (ap);
00212     }
00213 }
00214 
00225 static void
00226 logerrno (int priority, int errnum, const char * title, const char * fmt, ...)
00227 {
00228   va_list ap;
00229 
00230   if (priority <= LOGERR_THRESHOLD_REPORT)
00231     {
00232       va_start (ap, fmt);
00233       logerr_vperror (priority, errnum, title, fmt, ap);
00234       va_end (ap);
00235     }
00236 }
00237 
00243 #define LOGERR_MAKE_EASY(NICENAME, UGLYCODE) static void \
00244 logerr_##NICENAME (const char * title, const char * fmt, ...) \
00245 { \
00246   va_list ap; \
00247   if (UGLYCODE <= LOGERR_THRESHOLD_REPORT) \
00248     { \
00249       va_start (ap, fmt); \
00250       logerr_vdispatch (UGLYCODE, title, fmt, ap); \
00251       va_end (ap); \
00252     } \
00253 }
00254 
00255 LOGERR_MAKE_EASY (emerg, LOGERR_EMERG)
00256 LOGERR_MAKE_EASY (alert, LOGERR_ALERT)
00257 LOGERR_MAKE_EASY (crit, LOGERR_CRIT)
00258 LOGERR_MAKE_EASY (err, LOGERR_ERR)
00259 LOGERR_MAKE_EASY (warning, LOGERR_WARNING)
00260 LOGERR_MAKE_EASY (notice, LOGERR_NOTICE)
00261 LOGERR_MAKE_EASY (info, LOGERR_INFO)
00262 LOGERR_MAKE_EASY (debug, LOGERR_DEBUG)
00263 
00264 #endif /* !HAVE_*_VARARGS */
00265 
00267 #define logerr_assert(priority, title, condition) do { \
00268     if (priority <= LOGERR_THRESHOLD_REPORT) { \
00269         if (!(condition)) \
00270           logerr_dispatch(priority, title, \
00271                           "file %s: line %d: assertion (%s) failed", \
00272                           __FILE__, __LINE__, (#condition)); \
00273       } \
00274   } while (0);
00275 
00276 void logerr_set_abort_threshold (int threshold);
00277 void logerr_set_messenger (logerr_message_poster_t messenger);
00278 void logerr_set_perror_messenger (logerr_perror_poster_t poster);
00279 
00280 #if HAVE_C99_FUNC
00281 
00282 #define LOGERR_FUNC __func__
00283 #elif HAVE_PRETTY_FUNCTION
00284 
00285 #define LOGERR_FUNC __PRETTY_FUNCTION__
00286 #else
00287 
00288 #define LOGERR_FUNC NULL
00289 #endif /* HAVE_*_FUNCTION */
00290 
00291 END_C_DECLARATIONS
00292 
00293 #endif /* !LOGERR_H */
00294 

Generated on Fri Jul 8 14:55:00 2005 for tclSadie by  doxygen 1.4.2