1 /* SPDX-License-Identifier: LGPL-2.1-or-later */ 2 #pragma once 3 4 #include "log.h" 5 6 #define log_interface_full_errno_zerook(ifname, level, error, ...) \ 7 ({ \ 8 const char *_ifname = (ifname); \ 9 _ifname ? log_object_internal(level, error, PROJECT_FILE, __LINE__, __func__, "INTERFACE=", _ifname, NULL, NULL, ##__VA_ARGS__) : \ 10 log_internal(level, error, PROJECT_FILE, __LINE__, __func__, ##__VA_ARGS__); \ 11 }) 12 13 #define log_interface_full_errno(ifname, level, error, ...) \ 14 ({ \ 15 int _error = (error); \ 16 ASSERT_NON_ZERO(_error); \ 17 log_interface_full_errno_zerook(ifname, level, _error, __VA_ARGS__); \ 18 }) 19 20 /* 21 * The following macros append INTERFACE= to the message. 22 * The macros require a struct named 'Link' which contains 'char *ifname': 23 * 24 * typedef struct Link { 25 * char *ifname; 26 * } Link; 27 * 28 * See, network/networkd-link.h for example. 29 */ 30 31 #define log_link_full_errno_zerook(link, level, error, ...) \ 32 ({ \ 33 const Link *_l = (link); \ 34 log_interface_full_errno_zerook(_l ? _l->ifname : NULL, level, error, __VA_ARGS__); \ 35 }) 36 37 #define log_link_full_errno(link, level, error, ...) \ 38 ({ \ 39 int _error = (error); \ 40 ASSERT_NON_ZERO(_error); \ 41 log_link_full_errno_zerook(link, level, _error, __VA_ARGS__); \ 42 }) 43 44 #define log_link_full(link, level, ...) (void) log_link_full_errno_zerook(link, level, 0, __VA_ARGS__) 45 46 #define log_link_debug(link, ...) log_link_full(link, LOG_DEBUG, __VA_ARGS__) 47 #define log_link_info(link, ...) log_link_full(link, LOG_INFO, __VA_ARGS__) 48 #define log_link_notice(link, ...) log_link_full(link, LOG_NOTICE, __VA_ARGS__) 49 #define log_link_warning(link, ...) log_link_full(link, LOG_WARNING, __VA_ARGS__) 50 #define log_link_error(link, ...) log_link_full(link, LOG_ERR, __VA_ARGS__) 51 52 #define log_link_debug_errno(link, error, ...) log_link_full_errno(link, LOG_DEBUG, error, __VA_ARGS__) 53 #define log_link_info_errno(link, error, ...) log_link_full_errno(link, LOG_INFO, error, __VA_ARGS__) 54 #define log_link_notice_errno(link, error, ...) log_link_full_errno(link, LOG_NOTICE, error, __VA_ARGS__) 55 #define log_link_warning_errno(link, error, ...) log_link_full_errno(link, LOG_WARNING, error, __VA_ARGS__) 56 #define log_link_error_errno(link, error, ...) log_link_full_errno(link, LOG_ERR, error, __VA_ARGS__) 57 58 #define LOG_LINK_MESSAGE(link, fmt, ...) "MESSAGE=%s: " fmt, (link)->ifname, ##__VA_ARGS__ 59 #define LOG_LINK_INTERFACE(link) "INTERFACE=%s", (link)->ifname 60