3 * @brief Implement logging and error handling functions
7 // --- Custom headers --- //
16 static const char * unspecified_funct = "???";
20 * Print a message to stderr and log it via syslog. The message must be
21 * less than BUFSIZ characters long, or it will be truncated.
22 * @param level - Specify how severe the message is.
23 If level is higher (less urgent) than the program's verbosity (see options.h) no message will be printed
24 * @param funct - String indicating the function name from which this function was called.
25 If this is NULL, Log will show the unspecified_funct string instead
26 * @param file - Source file containing the function
27 * @param line - Line in the source file at which Log is called
28 * @param fmt - A format string
29 * @param ... - Arguments to be printed according to the format string
31 void LogEx(int level, const char * funct, const char * file, int line, ...)
33 //Todo: consider setlogmask(3) to filter messages
38 // Don't print the message unless we need to
39 if (level > g_options.verbosity)
43 fmt = va_arg(va, const char*);
45 if (fmt == NULL) // sanity check
46 Fatal("Format string is NULL");
48 vsnprintf(buffer, BUFSIZ, fmt, va);
52 funct = unspecified_funct;
54 // Make a human readable severity string
80 syslog(level, "%s: %s (%s:%d) - %s", severity, funct, file, line, buffer);
84 * Handle a Fatal error in the program by printing a message and exiting the program
85 * CALLING THIS FUNCTION WILL CAUSE THE PROGAM TO EXIT
86 * @param funct - Name of the calling function
87 * @param file - Name of the source file containing the calling function
88 * @param line - Line in the source file at which Fatal is called
89 * @param fmt - A format string
90 * @param ... - Arguments to be printed according to the format string
92 void FatalEx(const char * funct, const char * file, int line, ...)
98 fmt = va_arg(va, const char*);
102 // Fatal error in the Fatal function.
103 // (This really shouldn't happen unless someone does something insanely stupid)
104 Fatal("Format string is NULL");
105 return; // Should never get here
108 vsnprintf(buffer, BUFSIZ, fmt,va);
112 funct = unspecified_funct;
114 syslog(LOG_CRIT, "FATAL: %s (%s:%d) - %s", funct, file, line, buffer);