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

logerr.h File Reference

Flexible error reporting macros. More...

#include <stdarg.h>
#include "project_utilities.h"

Go to the source code of this file.

Defines

#define LOGERR_H   1
 The standard guard against including the same header twice.
#define LOGERR_THRESHOLD_REPORT   LOGERR_DEBUG
 The error severity threshold for reporting errors.
#define LOGERR_THRESHOLD_ABORT   LOGERR_ERR
 The error threshold for aborting the application.
#define LOGERR_MAKE_EASY(NICENAME, UGLYCODE)
 Used to generate the entire family of named error handlers.
#define logerr_assert(priority, title, condition)
 Make a prioritized assertion as a special case of an error message.
#define LOGERR_FUNC   NULL
 Do not report function names if there's no obvious way to track them.

Typedefs

typedef void(* logerr_message_poster_t )(int priority, const char *title, const char *message)
 A generic pointer to function reporting most errors.
typedef void(* logerr_perror_poster_t )(int priority, const char *title, const char *message, const char *syserr)
 A generic pointer to function reporting most system errors.

Enumerations

enum  logerr_priority {
  LOGERR_EMERG = 0, LOGERR_ALERT = 1, LOGERR_CRIT = 2, LOGERR_ERR = 3,
  LOGERR_WARNING = 4, LOGERR_NOTICE = 5, LOGERR_INFO = 6, LOGERR_DEBUG = 7
}
 Error severity codes (an ordered sequence). More...

Functions

void logerr_vdispatch (int priority, const char *title, const char *fmt, va_list ap)
 Format the error message and pass it to the currently registered handler.
void logerr_dispatch (int priority, const char *title, const char *fmt,...)
 A wrapper for logerr_vdispatch, taking a variable number of arguments.
void logerr_vperror (int priority, int errnum, const char *title, const char *fmt, va_list ap)
 Format a system error message, passing it to the registered handler.
void logerr_perror (int priority, int errnum, const char *title, const char *fmt,...)
 A wrapper for logerr_vperror, taking a variable number of arguments.
void logerr_set_abort_threshold (int threshold)
 Set the severity threshold for aborting the application.
void logerr_set_messenger (logerr_message_poster_t messenger)
 Register the normal error-reporting callback.
void logerr_set_perror_messenger (logerr_perror_poster_t poster)
 Register the system error-reporting callback.


Detailed Description

Flexible error reporting macros.

The collection of macros providing a friendly front end to a couple of error reporting functions that an application can override with its own callbacks if necessary (based partly on ideas lifted from the error logging for GLib, the core library for GTK+ and GNOME). Errors have a ranked series of severities, and there are no messages reporting errors below a certain severity threshold. For reasons of efficiency, it would be nice if the compiler did not generate code for messages that never appear, but simply having them removed in the preprocessor (using ifdefs, for example) can prevent the compiler finding syntax errors and other bugs that will appear when the error reporting threshold is lowered for debugging. So we go through a few minor contortions to encourage the pre-processor to generate source that will be parsed by the compiler, but which on recent versions of gcc and other such optimizing compilers will not end up in the object code.

Author:
University of Arizona Digital Image Analysis Lab
Date:
1999, 2004
Version:
Id
logerr.h,v 1.1 2005/03/22 20:29:38 mmunro Exp

Definition in file logerr.h.


Define Documentation

#define logerr_assert priority,
title,
condition   ) 
 

Value:

do { \
    if (priority <= LOGERR_THRESHOLD_REPORT) { \
        if (!(condition)) \
          logerr_dispatch(priority, title, \
                          "file %s: line %d: assertion (%s) failed", \
                          __FILE__, __LINE__, (#condition)); \
      } \
  } while (0);
Make a prioritized assertion as a special case of an error message.

Definition at line 267 of file logerr.h.

Referenced by bresenham_next(), bresenham_next_s(), demolish_bresenham(), dispose_doclist(), make_property(), sad_dispose_doc(), sad_get_doc_property(), sad_put_doc(), and sad_put_doc_property().

#define LOGERR_MAKE_EASY NICENAME,
UGLYCODE   ) 
 

Value:

static void \
logerr_##NICENAME (const char * title, const char * fmt, ...) \
{ \
  va_list ap; \
  if (UGLYCODE <= LOGERR_THRESHOLD_REPORT) \
    { \
      va_start (ap, fmt); \
      logerr_vdispatch (UGLYCODE, title, fmt, ap); \
      va_end (ap); \
    } \
}
Used to generate the entire family of named error handlers.

When varadic macros don't work, we generate error-handling functions with the same easy-to-understand names.

Definition at line 243 of file logerr.h.


Enumeration Type Documentation

enum logerr_priority
 

Error severity codes (an ordered sequence).

Enumeration values:
LOGERR_EMERG  Emergency (the most severe error).
LOGERR_ALERT  Alert.
LOGERR_CRIT  Critical.
LOGERR_ERR  Error.
LOGERR_WARNING  Warning.
LOGERR_NOTICE  Notice.
LOGERR_INFO  Information.
LOGERR_DEBUG  Debug (the least severe error).

Definition at line 49 of file logerr.h.


Function Documentation

void logerr_dispatch int  priority,
const char *  title,
const char *  fmt,
  ...
 

A wrapper for logerr_vdispatch, taking a variable number of arguments.

Parameters:
[in] priority the severity for this error.
[in] title where in the application the error originated.
[in] fmt the format string for the remaining arguments.
[in] ... the remaining arguments for generating the message.

Definition at line 156 of file logerr.c.

References logerr_vdispatch().

void logerr_perror int  priority,
int  errnum,
const char *  title,
const char *  fmt,
  ...
 

A wrapper for logerr_vperror, taking a variable number of arguments.

Parameters:
[in] priority the severity for this error.
[in] errnum the system error number.
[in] title where in the application the error originated.
[in] fmt the format string for the remaining arguments.
[in] ... the remaining arguments for generating the message.

Definition at line 202 of file logerr.c.

References logerr_vperror().

void logerr_set_abort_threshold int  threshold  ) 
 

Set the severity threshold for aborting the application.

Parameters:
[in] threshold the new threshold value.

Definition at line 216 of file logerr.c.

References logerr_lock, and logerr_unlock.

void logerr_set_messenger logerr_message_poster_t  messenger  ) 
 

Register the normal error-reporting callback.

Parameters:
[in] messenger the new error-reporting function.

Definition at line 228 of file logerr.c.

References logerr_lock, and logerr_unlock.

void logerr_set_perror_messenger logerr_perror_poster_t  poster  ) 
 

Register the system error-reporting callback.

Parameters:
[in] poster the new system error-reporting function.

Definition at line 240 of file logerr.c.

References logerr_lock, and logerr_unlock.

void logerr_vdispatch int  priority,
const char *  title,
const char *  fmt,
va_list  ap
 

Format the error message and pass it to the currently registered handler.

We format the error message text in a temporary buffer, invoke whatever error handling function is currently registered as the contents of our private application wide pointer, and abort if the severity threshold is passed.

Parameters:
[in] priority the severity for this error.
[in] title where in the application the error originated.
[in] fmt the format string for the remaining arguments.
[in] ap the remaining arguments for generating the message.

Definition at line 134 of file logerr.c.

References LOGERR_THRESHOLD_ABORT.

Referenced by logerr_dispatch().

void logerr_vperror int  priority,
int  errnum,
const char *  title,
const char *  fmt,
va_list  ap
 

Format a system error message, passing it to the registered handler.

We format the application error message text in a temporary buffer, get the explanation of a system error number from the strerror system function, and invoke whatever error system handling function is currently registered as the contents of our private application-wide pointer, aborting if the severity threshold is passed.

Parameters:
[in] priority the severity for this error.
[in] errnum the system error number.
[in] title where in the application the error originated.
[in] fmt the format string for the remaining arguments.
[in] ap the remaining arguments for generating the message.

Definition at line 180 of file logerr.c.

References LOGERR_THRESHOLD_ABORT.

Referenced by logerr_perror().


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