X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=server%2Flog.c;h=bd210d89d2f73d738ee051cac96ee940c4460323;hb=6bc90047ed36b392d90a1bf778baf9687b835f2d;hp=d41021f43032d3fe335497a402a494417eaef242;hpb=5d57467589ecefdf5bb5985005705a1c8460c623;p=matches%2FMCTX3420.git diff --git a/server/log.c b/server/log.c index d41021f..bd210d8 100644 --- a/server/log.c +++ b/server/log.c @@ -15,6 +15,7 @@ static const char * unspecified_funct = "???"; + /** * Print a message to stderr and log it via syslog. The message must be * less than BUFSIZ characters long, or it will be truncated. @@ -22,10 +23,12 @@ static const char * unspecified_funct = "???"; If level is higher (less urgent) than the program's verbosity (see options.h) no message will be printed * @param funct - String indicating the function name from which this function was called. If this is NULL, Log will show the unspecified_funct string instead + * @param file - Source file containing the function + * @param line - Line in the source file at which Log is called * @param fmt - A format string * @param ... - Arguments to be printed according to the format string */ -void LogEx(int level, const char * funct, ...) +void LogEx(int level, const char * funct, const char * file, int line, ...) { //Todo: consider setlogmask(3) to filter messages const char *fmt; @@ -36,7 +39,7 @@ void LogEx(int level, const char * funct, ...) if (level > g_options.verbosity) return; - va_start(va, funct); + va_start(va, line); fmt = va_arg(va, const char*); if (fmt == NULL) // sanity check @@ -74,22 +77,24 @@ void LogEx(int level, const char * funct, ...) break; } - syslog(level, "%s: %s - %s", severity, funct, buffer); + syslog(level, "%s: %s (%s:%d) - %s", severity, funct, file, line, buffer); } /** * Handle a Fatal error in the program by printing a message and exiting the program * CALLING THIS FUNCTION WILL CAUSE THE PROGAM TO EXIT * @param funct - Name of the calling function + * @param file - Name of the source file containing the calling function + * @param line - Line in the source file at which Fatal is called * @param fmt - A format string * @param ... - Arguments to be printed according to the format string */ -void FatalEx(const char * funct, ...) +void FatalEx(const char * funct, const char * file, int line, ...) { const char *fmt; char buffer[BUFSIZ]; va_list va; - va_start(va, funct); + va_start(va, line); fmt = va_arg(va, const char*); if (fmt == NULL) @@ -106,7 +111,8 @@ void FatalEx(const char * funct, ...) if (funct == NULL) funct = unspecified_funct; - syslog(LOG_CRIT, "FATAL: %s - %s", funct, buffer); + syslog(LOG_CRIT, "FATAL: %s (%s:%d) - %s", funct, file, line, buffer); + exit(EXIT_FAILURE); }