X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Flog.h;h=569762d083aee8b10cf8d571ba2698a4d0092a30;hb=d896ac2d2fbce41a0b11a0618a685adeaf18b8fe;hp=b323b2f7d42bc8b011afae24073b8d3f9709e9ac;hpb=1cfa9a4cbb41ef770614fa97961cc056a63c1b7c;p=elogind.git diff --git a/src/shared/log.h b/src/shared/log.h index b323b2f7d..569762d08 100644 --- a/src/shared/log.h +++ b/src/shared/log.h @@ -23,14 +23,13 @@ #include #include +#include #include #include -#include -#include #include -#include "macro.h" #include "sd-id128.h" +#include "macro.h" typedef enum LogTarget{ LOG_TARGET_CONSOLE, @@ -205,8 +204,26 @@ LogTarget log_target_from_string(const char *s) _pure_; /* Helpers to prepare various fields for structured logging */ #define LOG_MESSAGE(fmt, ...) "MESSAGE=" fmt, ##__VA_ARGS__ #define LOG_MESSAGE_ID(x) "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(x) -#define LOG_ERRNO(error) "ERRNO=%i", abs(error) void log_received_signal(int level, const struct signalfd_siginfo *si); void log_set_upgrade_syslog_to_journal(bool b); + +int log_syntax_internal( + const char *unit, + int level, + const char *config_file, + unsigned config_line, + int error, + const char *file, + int line, + const char *func, + const char *format, ...) _printf_(9, 10); + +#define log_syntax(unit, level, config_file, config_line, error, ...) \ + ({ \ + int _level = (level), _e = (error); \ + (log_get_max_level() >= LOG_PRI(_level)) \ + ? log_syntax_internal(unit, _level, config_file, config_line, _e, __FILE__, __LINE__, __func__, __VA_ARGS__) \ + : -abs(_e); \ + })