3 * @brief Implement logging and error handling functions
7 // --- Custom headers --- //
16 static const char * unspecified_funct = "???";
19 * Print a message to stderr and log it via syslog. The message must be
20 * less than BUFSIZ characters long, or it will be truncated.
21 * @param level - Specify how severe the message is.
22 If level is higher (less urgent) than the program's verbosity (see options.h) no message will be printed
23 * @param funct - String indicating the function name from which this function was called.
24 If this is NULL, Log will show the unspecified_funct string instead
25 * @param fmt - A format string
26 * @param ... - Arguments to be printed according to the format string
28 void LogEx(int level, const char * funct, ...)
30 //Todo: consider setlogmask(3) to filter messages
35 // Don't print the message unless we need to
36 if (level > g_options.verbosity)
40 fmt = va_arg(va, const char*);
42 if (fmt == NULL) // sanity check
43 Fatal("Format string is NULL");
45 vsnprintf(buffer, BUFSIZ, fmt, va);
49 funct = unspecified_funct;
51 // Make a human readable severity string
77 syslog(level, "%s: %s - %s", severity, funct, buffer);
81 * Handle a Fatal error in the program by printing a message and exiting the program
82 * CALLING THIS FUNCTION WILL CAUSE THE PROGAM TO EXIT
83 * @param funct - Name of the calling function
84 * @param fmt - A format string
85 * @param ... - Arguments to be printed according to the format string
87 void FatalEx(const char * funct, ...)
93 fmt = va_arg(va, const char*);
97 // Fatal error in the Fatal function.
98 // (This really shouldn't happen unless someone does something insanely stupid)
99 Fatal("Format string is NULL");
100 return; // Should never get here
103 vsnprintf(buffer, BUFSIZ, fmt,va);
107 funct = unspecified_funct;
109 syslog(LOG_CRIT, "FATAL: %s - %s", funct, buffer);