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 file - Source file containing the function
26 * @param line - Line in the source file at which Log is called
27 * @param fmt - A format string
28 * @param ... - Arguments to be printed according to the format string
30 void LogEx(int level, const char * funct, const char * file, int line, ...)
32 //Todo: consider setlogmask(3) to filter messages
37 // Don't print the message unless we need to
38 if (level > g_options.verbosity)
42 fmt = va_arg(va, const char*);
44 if (fmt == NULL) // sanity check
45 Fatal("Format string is NULL");
47 vsnprintf(buffer, BUFSIZ, fmt, va);
51 funct = unspecified_funct;
53 // Make a human readable severity string
79 syslog(level, "%s: %s (%s:%d) - %s", severity, funct, file, line, buffer);
83 * Handle a Fatal error in the program by printing a message and exiting the program
84 * CALLING THIS FUNCTION WILL CAUSE THE PROGAM TO EXIT
85 * @param funct - Name of the calling function
86 * @param file - Name of the source file containing the calling function
87 * @param line - Line in the source file at which Fatal is called
88 * @param fmt - A format string
89 * @param ... - Arguments to be printed according to the format string
91 void FatalEx(const char * funct, const char * file, int line, ...)
97 fmt = va_arg(va, const char*);
101 // Fatal error in the Fatal function.
102 // (This really shouldn't happen unless someone does something insanely stupid)
103 Fatal("Format string is NULL");
104 return; // Should never get here
107 vsnprintf(buffer, BUFSIZ, fmt,va);
111 funct = unspecified_funct;
113 syslog(LOG_CRIT, "FATAL: %s (%s:%d) - %s", funct, file, line, buffer);