diff options
Diffstat (limited to 'src/shared/log.h')
-rw-r--r-- | src/shared/log.h | 49 |
1 files changed, 35 insertions, 14 deletions
diff --git a/src/shared/log.h b/src/shared/log.h index 8141e9dbb0..9dd68df500 100644 --- a/src/shared/log.h +++ b/src/shared/log.h @@ -77,44 +77,49 @@ void log_parse_environment(void); int log_meta( int level, + int error, const char*file, int line, const char *func, - const char *format, ...) _printf_(5,6); + const char *format, ...) _printf_(6,7); int log_metav( int level, + int error, const char*file, int line, const char *func, const char *format, - va_list ap) _printf_(5,0); + va_list ap) _printf_(6,0); int log_meta_object( int level, + int error, const char*file, int line, const char *func, const char *object_name, const char *object, - const char *format, ...) _printf_(7,8); + const char *format, ...) _printf_(8,9); int log_metav_object( int level, + int error, const char*file, int line, const char *func, const char *object_name, const char *object, const char *format, - va_list ap) _printf_(7,0); + va_list ap) _printf_(8,0); int log_struct_internal( int level, + int error, const char *file, int line, const char *func, - const char *format, ...) _printf_(5,0) _sentinel_; + const char *format, ...) _printf_(6,0) _sentinel_; int log_oom_internal( const char *file, @@ -124,11 +129,13 @@ int log_oom_internal( /* This modifies the buffer passed! */ int log_dump_internal( int level, + int error, const char*file, int line, const char *func, char *buffer); +/* Logging for various assertions */ noreturn void log_assert_failed( const char *text, const char *file, @@ -147,12 +154,16 @@ void log_assert_failed_return( int line, const char *func); -#define log_full(level, ...) \ -do { \ - if (log_get_max_level() >= (level)) \ - log_meta((level), __FILE__, __LINE__, __func__, __VA_ARGS__); \ -} while (0) +/* Logging with level */ +#define log_full_errno(level, error, ...) \ + do { \ + if (log_get_max_level() >= (level)) \ + log_meta((level), error, __FILE__, __LINE__, __func__, __VA_ARGS__); \ + } while (false) +#define log_full(level, ...) log_full_errno(level, 0, __VA_ARGS__) + +/* Normal logging */ #define log_debug(...) log_full(LOG_DEBUG, __VA_ARGS__) #define log_info(...) log_full(LOG_INFO, __VA_ARGS__) #define log_notice(...) log_full(LOG_NOTICE, __VA_ARGS__) @@ -160,18 +171,28 @@ do { \ #define log_error(...) log_full(LOG_ERR, __VA_ARGS__) #define log_emergency(...) log_full(getpid() == 1 ? LOG_EMERG : LOG_ERR, __VA_ARGS__) +/* Logging triggered by an errno-like error */ +#define log_debug_errno(error, ...) log_full_errno(LOG_DEBUG, error, __VA_ARGS__) +#define log_info_errno(error, ...) log_full_errno(LOG_INFO, error, __VA_ARGS__) +#define log_notice_errno(error, ...) log_full_errno(LOG_NOTICE, error, __VA_ARGS__) +#define log_warning_errno(error, ...) log_full_errno(LOG_WARNING, error, __VA_ARGS__) +#define log_error_errno(error, ...) log_full_errno(LOG_ERR, error, __VA_ARGS__) +#define log_emergency_errno(error, ...) log_full_errno(getpid() == 1 ? LOG_EMERG : LOG_ERR, __VA_ARGS__) + #ifdef LOG_TRACE # define log_trace(...) log_debug(__VA_ARGS__) #else # define log_trace(...) do {} while(0) #endif -#define log_struct(level, ...) log_struct_internal(level, __FILE__, __LINE__, __func__, __VA_ARGS__) - -#define log_oom() log_oom_internal(__FILE__, __LINE__, __func__) +/* Structured logging */ +#define log_struct(level, ...) log_struct_internal(level, 0, __FILE__, __LINE__, __func__, __VA_ARGS__) +#define log_struct_errno(level, error, ...) log_struct_internal(level, error, __FILE__, __LINE__, __func__, __VA_ARGS__) /* This modifies the buffer passed! */ -#define log_dump(level, buffer) log_dump_internal(level, __FILE__, __LINE__, __func__, buffer) +#define log_dump(level, buffer) log_dump_internal(level, 0, __FILE__, __LINE__, __func__, buffer) + +#define log_oom() log_oom_internal(__FILE__, __LINE__, __func__) bool log_on_console(void) _pure_; |