diff --git a/log.c b/log.c index 342f71f..3364e69 100644 --- a/log.c +++ b/log.c @@ -2,11 +2,13 @@ #include #include +#include #include +#include static void _log(enum log_class log_class, const char *module, const char *file, int lineno, - const char *fmt, va_list va) + const char *fmt, int sys_errno, va_list va) { bool colorize = true; @@ -35,6 +37,10 @@ _log(enum log_class log_class, const char *module, const char *file, int lineno, //printf("%%s\n", buf); vprintf(fmt, va); + + if (sys_errno != 0) + printf(": %s", strerror(sys_errno)); + printf("\n"); } @@ -44,6 +50,16 @@ log_msg(enum log_class log_class, const char *module, { va_list ap; va_start(ap, fmt); - _log(log_class, module, file, lineno, fmt, ap); + _log(log_class, module, file, lineno, fmt, 0, ap); + va_end(ap); +} + +void log_errno(enum log_class log_class, const char *module, + const char *file, int lineno, + const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + _log(log_class, module, file, lineno, fmt, errno, ap); va_end(ap); } diff --git a/log.h b/log.h index 686b96a..9e6cd95 100644 --- a/log.h +++ b/log.h @@ -5,11 +5,15 @@ enum log_class { LOG_CLASS_ERROR, LOG_CLASS_WARNING, LOG_CLASS_INFO, LOG_CLASS_D void log_msg(enum log_class log_class, const char *module, const char *file, int lineno, const char *fmt, ...) __attribute__((format (printf, 5, 6))); + +void log_errno(enum log_class log_class, const char *module, const char *file, int lineno, const char *fmt, ...) __attribute__((format (printf, 5, 6))); #define LOG_ERR(fmt, ...) \ log_msg(LOG_CLASS_ERROR, LOG_MODULE, __FILE__, __LINE__, fmt, ## __VA_ARGS__) +#define LOG_ERRNO(fmt, ...) \ + log_errno(LOG_CLASS_ERROR, LOG_MODULE, __FILE__, __LINE__, fmt, ## __VA_ARGS__) #define LOG_WARN(fmt, ...) \ log_msg(LOG_CLASS_WARNING, LOG_MODULE, __FILE__, __LINE__, fmt, ## __VA_ARGS__) #define LOG_INFO(fmt, ...) \