diff --git a/src/common_define.h b/src/common_define.h index 7e49161..afecb7e 100644 --- a/src/common_define.h +++ b/src/common_define.h @@ -200,6 +200,12 @@ typedef void* (*MallocFunc)(size_t size); #endif +#ifdef __GNUC__ + #define __gcc_attribute__ __attribute__ +#else + #define __gcc_attribute__(x) +#endif + #ifdef __cplusplus } #endif diff --git a/src/logger.h b/src/logger.h index 6f7db27..ae7dafb 100644 --- a/src/logger.h +++ b/src/logger.h @@ -282,7 +282,7 @@ void log_destroy_ex(LogContext *pContext); * return: none */ void log_it_ex(LogContext *pContext, const int priority, \ - const char *format, ...); + const char *format, ...) __gcc_attribute__ ((format (printf, 3, 4))); /** log to file * parameters: @@ -347,16 +347,32 @@ const char *log_get_level_caption_ex(LogContext *pContext); #define log_get_level_caption() log_get_level_caption_ex(&g_log_context) -void logEmergEx(LogContext *pContext, const char *format, ...); -void logCritEx(LogContext *pContext, const char *format, ...); -void logAlertEx(LogContext *pContext, const char *format, ...); -void logErrorEx(LogContext *pContext, const char *format, ...); -void logWarningEx(LogContext *pContext, const char *format, ...); -void logNoticeEx(LogContext *pContext, const char *format, ...); -void logInfoEx(LogContext *pContext, const char *format, ...); -void logDebugEx(LogContext *pContext, const char *format, ...); -void logAccess(LogContext *pContext, struct timeval *tvStart, \ - const char *format, ...); +void logEmergEx(LogContext *pContext, const char *format, ...) + __gcc_attribute__ ((format (printf, 2, 3))); + +void logCritEx(LogContext *pContext, const char *format, ...) + __gcc_attribute__ ((format (printf, 2, 3))); + +void logAlertEx(LogContext *pContext, const char *format, ...) + __gcc_attribute__ ((format (printf, 2, 3))); + +void logErrorEx(LogContext *pContext, const char *format, ...) + __gcc_attribute__ ((format (printf, 2, 3))); + +void logWarningEx(LogContext *pContext, const char *format, ...) + __gcc_attribute__ ((format (printf, 2, 3))); + +void logNoticeEx(LogContext *pContext, const char *format, ...) + __gcc_attribute__ ((format (printf, 2, 3))); + +void logInfoEx(LogContext *pContext, const char *format, ...) + __gcc_attribute__ ((format (printf, 2, 3))); + +void logDebugEx(LogContext *pContext, const char *format, ...) + __gcc_attribute__ ((format (printf, 2, 3))); + +void logAccess(LogContext *pContext, struct timeval *tvStart, + const char *format, ...) __gcc_attribute__ ((format (printf, 3, 4))); //#define LOG_FORMAT_CHECK @@ -374,14 +390,29 @@ void logAccess(LogContext *pContext, struct timeval *tvStart, \ #else /* following functions use global log context: g_log_context */ -void logEmerg(const char *format, ...); -void logCrit(const char *format, ...); -void logAlert(const char *format, ...); -void logError(const char *format, ...); -void logWarning(const char *format, ...); -void logNotice(const char *format, ...); -void logInfo(const char *format, ...); -void logDebug(const char *format, ...); +void logEmerg(const char *format, ...) + __gcc_attribute__ ((format (printf, 1, 2))); + +void logCrit(const char *format, ...) + __gcc_attribute__ ((format (printf, 1, 2))); + +void logAlert(const char *format, ...) + __gcc_attribute__ ((format (printf, 1, 2))); + +void logError(const char *format, ...) + __gcc_attribute__ ((format (printf, 1, 2))); + +void logWarning(const char *format, ...) + __gcc_attribute__ ((format (printf, 1, 2))); + +void logNotice(const char *format, ...) + __gcc_attribute__ ((format (printf, 1, 2))); + +void logInfo(const char *format, ...) + __gcc_attribute__ ((format (printf, 1, 2))); + +void logDebug(const char *format, ...) + __gcc_attribute__ ((format (printf, 1, 2))); #endif @@ -390,4 +421,3 @@ void logDebug(const char *format, ...); #endif #endif -