3 * @brief Implement logging and error handling functions
10 // --- Custom headers --- //
15 // --- Static variables --- //
16 static const char * unspecified_funct = "???";
18 // --- Function implementations --- //
20 //TODO: Migrate to syslog (shouldn't be too hard; these functions basically do what syslog does)
21 // Note that we will want to have a seperate log as well as syslog; give the user the option to view the log using the GUI
24 * Print a message to stderr
25 * @param level - Specify how severe the message is.
26 If level is higher (less urgent) than the program's verbosity (see options.h) no message will be printed
27 * @param funct - String indicating the function name from which this function was called.
28 If this is NULL, Log will show the unspecified_funct string instead
29 * @param fmt - A format string
30 * @param ... - Arguments to be printed according to the format string
32 void LogEx(int level, const char * funct, ...)
37 fmt = va_arg(va, const char*);
39 if (fmt == NULL) // sanity check
40 FatalEx("Log", "Format string is NULL");
42 // Don't print the message unless we need to
43 if (level > g_options.verbosity)
47 funct = unspecified_funct;
49 // Make a human readable severity string
70 // Print: Program name, PID, severity string, function name first
71 fprintf(stderr, "%s [%d] : %s : %s - ", g_options.program, getpid(), severity, funct);
73 // Then pass additional arguments with the format string to vfprintf for printing
74 vfprintf(stderr, fmt, va);
77 // End log messages with a newline
78 fprintf(stderr, "\n");
82 * Handle a Fatal error in the program by printing a message and exiting the program
83 * CALLING THIS FUNCTION WILL CAUSE THE PROGAM TO EXIT
84 * @param funct - Name of the calling function
85 * @param fmt - A format string
86 * @param ... - Arguments to be printed according to the format string
88 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 FatalEx("Fatal", "Format string is NULL");
100 return; // Should never get here
104 funct = unspecified_funct;
106 fprintf(stderr, "%s [%d] : %s : FATAL - ", g_options.program, getpid(), funct);
108 vfprintf(stderr, fmt, va);
110 fprintf(stderr, "\n");