diff --git a/client.c b/client.c index 60f53fc..16d88d4 100644 --- a/client.c +++ b/client.c @@ -76,9 +76,12 @@ static int no_dns = 0; int log_debug_enabled = 0; -void LOG_Message(LOG_Severity severity, LOG_Facility facility, - int line_number, const char *filename, - const char *function_name, const char *format, ...) +void LOG_Message(LOG_Severity severity, +#if DEBUG > 0 + LOG_Facility facility, int line_number, + const char *filename, const char *function_name, +#endif + const char *format, ...) { va_list ap; diff --git a/logging.c b/logging.c index d9685f1..7eb680d 100644 --- a/logging.c +++ b/logging.c @@ -119,9 +119,12 @@ static void log_message(int fatal, LOG_Severity severity, const char *message) /* ================================================== */ -void LOG_Message(LOG_Severity severity, LOG_Facility facility, - int line_number, const char *filename, - const char *function_name, const char *format, ...) +void LOG_Message(LOG_Severity severity, +#if DEBUG > 0 + LOG_Facility facility, int line_number, + const char *filename, const char *function_name, +#endif + const char *format, ...) { char buf[2048]; va_list other_args; @@ -134,8 +137,10 @@ void LOG_Message(LOG_Severity severity, LOG_Facility facility, stm = *gmtime(&t); strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%SZ", &stm); fprintf(stderr, "%s ", buf); +#if DEBUG > 0 if (debug_level >= DEBUG_LEVEL_PRINT_FUNCTION) fprintf(stderr, "%s:%d:(%s) ", filename, line_number, function_name); +#endif } va_start(other_args, format); diff --git a/logging.h b/logging.h index 7c89bb7..84504c2 100644 --- a/logging.h +++ b/logging.h @@ -45,18 +45,28 @@ extern int log_debug_enabled; #define FORMAT_ATTRIBUTE_PRINTF(str, first) #endif +#if DEBUG > 0 +#define LOG_MESSAGE(severity, facility, ...) \ + LOG_Message(LOGS_DEBUG, facility, __LINE__, __FILE__, FUNCTION_NAME, __VA_ARGS__); +#else +#define LOG_MESSAGE(severity, facility, ...) \ + LOG_Message(severity, __VA_ARGS__); +#endif + #define DEBUG_LOG(facility, ...) \ do { \ if (DEBUG && log_debug_enabled) \ - LOG_Message(LOGS_DEBUG, facility, __LINE__, __FILE__, FUNCTION_NAME, __VA_ARGS__); \ + LOG_MESSAGE(LOGS_DEBUG, facility, __VA_ARGS__); \ } while (0) -#define LOG(severity, facility, ...) LOG_Message(severity, facility, __LINE__, __FILE__, FUNCTION_NAME, __VA_ARGS__) + #define LOG_FATAL(facility, ...) \ do { \ - LOG_Message(LOGS_FATAL, facility, __LINE__, __FILE__, FUNCTION_NAME, __VA_ARGS__); \ + LOG_MESSAGE(LOGS_FATAL, facility, __VA_ARGS__); \ exit(1); \ } while (0) +#define LOG(severity, facility, ...) LOG_MESSAGE(severity, facility, __VA_ARGS__) + /* Definition of severity */ typedef enum { LOGS_INFO, @@ -114,10 +124,15 @@ extern void LOG_Initialise(void); extern void LOG_Finalise(void); /* Line logging function */ +#if DEBUG > 0 FORMAT_ATTRIBUTE_PRINTF(6, 7) extern void LOG_Message(LOG_Severity severity, LOG_Facility facility, int line_number, const char *filename, const char *function_name, const char *format, ...); +#else +FORMAT_ATTRIBUTE_PRINTF(2, 3) +extern void LOG_Message(LOG_Severity severity, const char *format, ...); +#endif /* Set debug level: 0, 1 - only non-debug messages are logged