diff --git a/config.h.in b/config.h.in index 5db5667..392d9b0 100644 --- a/config.h.in +++ b/config.h.in @@ -6,6 +6,9 @@ /* Define to 1 if the system has the `constructor' function attribute */ #undef HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR +/* Define to 1 if the system has the `format' function attribute */ +#undef HAVE_FUNC_ATTRIBUTE_FORMAT + /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H diff --git a/configure.ac b/configure.ac index faacbee..9c3ee02 100644 --- a/configure.ac +++ b/configure.ac @@ -15,7 +15,8 @@ LT_INIT PKG_PROG_PKG_CONFIG PKG_INSTALLDIR AX_COMPILER_FLAGS -AX_GCC_FUNC_ATTRIBUTE(constructor) +AX_GCC_FUNC_ATTRIBUTE([constructor]) +AX_GCC_FUNC_ATTRIBUTE([format]) AC_SUBST([PINELOG_CFLAGS]) diff --git a/pinelog.c b/pinelog.c index cf2c5ff..ded5abc 100644 --- a/pinelog.c +++ b/pinelog.c @@ -22,7 +22,7 @@ #endif #ifndef PINELOG_DEFAULT_LEVEL -#define PINELOG_DEFAULT_LEVEL LOG_LVL_ERROR +#define PINELOG_DEFAULT_LEVEL PINELOG_LVL_ERROR #endif /********************************************************************** @@ -126,7 +126,7 @@ int pinelog_get_level(void) int pinelog_set_level(int level) { - if (level < LOG_LVL_NONE || level > LOG_LVL_TRACE) { + if (level < PINELOG_LVL_NONE || level > PINELOG_LVL_TRACE) { return EINVAL; } @@ -147,8 +147,8 @@ void pinelog_log_message(int level, const char *file, int line, const char *fmt, } /* Cap the log level */ - if (level > LOG_LVL_TRACE) { - level = LOG_LVL_TRACE; + if (level > PINELOG_LVL_TRACE) { + level = PINELOG_LVL_TRACE; } /* Validate and set output stream */ diff --git a/pinelog.h b/pinelog.h index 367f789..b7bc0ff 100644 --- a/pinelog.h +++ b/pinelog.h @@ -18,6 +18,7 @@ #ifndef LOGGING_H #define LOGGING_H +#include "config.h" #include #include @@ -106,6 +107,10 @@ int pinelog_get_level(void); * * @returns None */ +#if HAVE_FUNC_ATTRIBUTE_FORMAT +__attribute__((format(printf, 4, 5))) +#endif + void pinelog_log_message(int level, const char *file, int line, const char *fmt, ...); #define PINELOG_FATAL(fmt, ...) do { \