Radek Krejci | 5fe60cc | 2015-09-01 17:14:39 +0200 | [diff] [blame] | 1 | /** |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 2 | * @file log.h |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief libnetconf2 logger |
Radek Krejci | 5fe60cc | 2015-09-01 17:14:39 +0200 | [diff] [blame] | 5 | * |
Michal Vasko | 95ea9ff | 2021-11-09 12:29:14 +0100 | [diff] [blame] | 6 | * @copyright |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 7 | * Copyright (c) 2015 - 2021 CESNET, z.s.p.o. |
Radek Krejci | 5fe60cc | 2015-09-01 17:14:39 +0200 | [diff] [blame] | 8 | * |
Radek Krejci | 9b81f5b | 2016-02-24 13:14:49 +0100 | [diff] [blame] | 9 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 10 | * You may not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
Michal Vasko | afd416b | 2016-02-25 14:51:46 +0100 | [diff] [blame] | 12 | * |
Radek Krejci | 9b81f5b | 2016-02-24 13:14:49 +0100 | [diff] [blame] | 13 | * https://opensource.org/licenses/BSD-3-Clause |
Radek Krejci | 5fe60cc | 2015-09-01 17:14:39 +0200 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #ifndef NC_LOG_PRIVATE_H_ |
| 17 | #define NC_LOG_PRIVATE_H_ |
| 18 | |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 19 | #include <stdarg.h> |
Radek Krejci | a352802 | 2015-09-02 13:46:38 +0200 | [diff] [blame] | 20 | |
Václav Kubernát | a4474cf | 2022-01-17 12:37:22 +0100 | [diff] [blame] | 21 | #include "compat.h" |
Radek Krejci | a352802 | 2015-09-02 13:46:38 +0200 | [diff] [blame] | 22 | #include "log.h" |
| 23 | |
Radek Krejci | 5fe60cc | 2015-09-01 17:14:39 +0200 | [diff] [blame] | 24 | /* |
| 25 | * libnetconf's message printing |
| 26 | */ |
| 27 | |
| 28 | /** |
Michal Vasko | 0553277 | 2021-06-03 12:12:38 +0200 | [diff] [blame] | 29 | * @brief Internal printing function |
| 30 | * |
| 31 | * @param[in] session Optional NETCONF session that generated the message |
Radek Krejci | 5fe60cc | 2015-09-01 17:14:39 +0200 | [diff] [blame] | 32 | * @param[in] level Verbose level |
| 33 | * @param[in] format Formatting string |
| 34 | */ |
Michal Vasko | 0553277 | 2021-06-03 12:12:38 +0200 | [diff] [blame] | 35 | void prv_printf(const struct nc_session *session, NC_VERB_LEVEL level, const char *format, ...); |
Radek Krejci | 5fe60cc | 2015-09-01 17:14:39 +0200 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * @brief Verbose level variable |
| 39 | */ |
Václav Kubernát | a4474cf | 2022-01-17 12:37:22 +0100 | [diff] [blame] | 40 | extern ATOMIC_T verbose_level; |
Radek Krejci | 5fe60cc | 2015-09-01 17:14:39 +0200 | [diff] [blame] | 41 | |
| 42 | /* |
| 43 | * Verbose printing macros |
| 44 | */ |
roman | 4067241 | 2023-05-04 11:10:22 +0200 | [diff] [blame] | 45 | #define ERR(session, ...) prv_printf(session, NC_VERB_ERROR, __VA_ARGS__) |
| 46 | #define WRN(session, ...) if(ATOMIC_LOAD_RELAXED(verbose_level)>=NC_VERB_WARNING){prv_printf(session, NC_VERB_WARNING, __VA_ARGS__);} |
| 47 | #define VRB(session, ...) if(ATOMIC_LOAD_RELAXED(verbose_level)>=NC_VERB_VERBOSE){prv_printf(session, NC_VERB_VERBOSE, __VA_ARGS__);} |
| 48 | #define DBG(session, ...) if(ATOMIC_LOAD_RELAXED(verbose_level)>=NC_VERB_DEBUG){prv_printf(session, NC_VERB_DEBUG, __VA_ARGS__);} |
| 49 | #define DBL(session, ...) if(ATOMIC_LOAD_RELAXED(verbose_level)>=NC_VERB_DEBUG_LOWLVL){prv_printf(session, NC_VERB_DEBUG_LOWLVL, __VA_ARGS__);} |
Radek Krejci | 5fe60cc | 2015-09-01 17:14:39 +0200 | [diff] [blame] | 50 | |
Michal Vasko | 0553277 | 2021-06-03 12:12:38 +0200 | [diff] [blame] | 51 | #define ERRMEM ERR(NULL, "%s: memory reallocation failed (%s:%d).", __func__, __FILE__, __LINE__) |
Michal Vasko | 0553277 | 2021-06-03 12:12:38 +0200 | [diff] [blame] | 52 | #define ERRINIT ERR(NULL, "%s: libnetconf2 not initialized.", __func__) |
| 53 | #define ERRINT ERR(NULL, "%s: internal error (%s:%d).", __func__, __FILE__, __LINE__) |
roman | 4067241 | 2023-05-04 11:10:22 +0200 | [diff] [blame] | 54 | #define ERRARG(session, ARG) ERR(session, "Invalid argument %s (%s()).", #ARG, __func__) |
| 55 | |
roman | 3a95bb2 | 2023-10-26 11:07:17 +0200 | [diff] [blame] | 56 | #define NC_CHECK_ERRMEM_RET(COND, RET) if ((COND)) {ERRMEM; return (RET);} |
| 57 | #define NC_CHECK_ERRMEM_GOTO(COND, RET, GOTO) if ((COND)) {ERRMEM; RET; goto GOTO;} |
| 58 | |
roman | 4067241 | 2023-05-04 11:10:22 +0200 | [diff] [blame] | 59 | #define GETMACRO1(_1, NAME, ...) NAME |
| 60 | #define GETMACRO2(_1, _2, NAME, ...) NAME |
| 61 | #define GETMACRO3(_1, _2, _3, NAME, ...) NAME |
| 62 | #define GETMACRO4(_1, _2, _3, _4, NAME, ...) NAME |
| 63 | #define GETMACRO5(_1, _2, _3, _4, _5, NAME, ...) NAME |
| 64 | #define GETMACRO6(_1, _2, _3, _4, _5, _6, NAME, ...) NAME |
Roytak | 40cdba2 | 2023-10-04 14:05:47 +0200 | [diff] [blame] | 65 | #define GETMACRO7(_1, _2, _3, _4, _5, _6, _7, NAME, ...) NAME |
| 66 | #define GETMACRO8(_1, _2, _3, _4, _5, _6, _7, _8, NAME, ...) NAME |
roman | 4067241 | 2023-05-04 11:10:22 +0200 | [diff] [blame] | 67 | |
| 68 | #define NC_CHECK_ARG_RET1(session, ARG, RETVAL) if (!(ARG)) {ERRARG(session, ARG);return RETVAL;} |
Roytak | 40cdba2 | 2023-10-04 14:05:47 +0200 | [diff] [blame] | 69 | #define NC_CHECK_ARG_RET2(session, ARG1, ARG2, RETVAL)\ |
| 70 | NC_CHECK_ARG_RET1(session, ARG1, RETVAL);\ |
| 71 | NC_CHECK_ARG_RET1(session, ARG2, RETVAL) |
| 72 | #define NC_CHECK_ARG_RET3(session, ARG1, ARG2, ARG3, RETVAL)\ |
| 73 | NC_CHECK_ARG_RET2(session, ARG1, ARG2, RETVAL);\ |
| 74 | NC_CHECK_ARG_RET1(session, ARG3, RETVAL) |
| 75 | #define NC_CHECK_ARG_RET4(session, ARG1, ARG2, ARG3, ARG4, RETVAL)\ |
| 76 | NC_CHECK_ARG_RET3(session, ARG1, ARG2, ARG3, RETVAL);\ |
roman | 4067241 | 2023-05-04 11:10:22 +0200 | [diff] [blame] | 77 | NC_CHECK_ARG_RET1(session, ARG4, RETVAL) |
Roytak | 40cdba2 | 2023-10-04 14:05:47 +0200 | [diff] [blame] | 78 | #define NC_CHECK_ARG_RET5(session, ARG1, ARG2, ARG3, ARG4, ARG5, RETVAL)\ |
| 79 | NC_CHECK_ARG_RET4(session, ARG1, ARG2, ARG3, ARG4, RETVAL);\ |
roman | 4067241 | 2023-05-04 11:10:22 +0200 | [diff] [blame] | 80 | NC_CHECK_ARG_RET1(session, ARG5, RETVAL) |
Roytak | 40cdba2 | 2023-10-04 14:05:47 +0200 | [diff] [blame] | 81 | #define NC_CHECK_ARG_RET6(session, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, RETVAL)\ |
| 82 | NC_CHECK_ARG_RET5(session, ARG1, ARG2, ARG3, ARG4, ARG5, RETVAL);\ |
| 83 | NC_CHECK_ARG_RET1(session, ARG6, RETVAL) |
| 84 | #define NC_CHECK_ARG_RET7(session, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, RETVAL)\ |
| 85 | NC_CHECK_ARG_RET6(session, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, RETVAL);\ |
| 86 | NC_CHECK_ARG_RET1(session, ARG7, RETVAL) |
roman | 4067241 | 2023-05-04 11:10:22 +0200 | [diff] [blame] | 87 | |
| 88 | /** |
| 89 | * @brief Function's parameters checking macro |
| 90 | * |
| 91 | * @param session Session that is logged. |
| 92 | * @param ... Parameters of the function to check. The last parameter is the value that is returned on error. |
| 93 | */ |
Roytak | 40cdba2 | 2023-10-04 14:05:47 +0200 | [diff] [blame] | 94 | #define NC_CHECK_ARG_RET(session, ...) GETMACRO8(__VA_ARGS__, NC_CHECK_ARG_RET7, NC_CHECK_ARG_RET6, NC_CHECK_ARG_RET5,\ |
| 95 | NC_CHECK_ARG_RET4, NC_CHECK_ARG_RET3, NC_CHECK_ARG_RET2, NC_CHECK_ARG_RET1, DUMMY) (session, __VA_ARGS__) |
Radek Krejci | 52b3702 | 2015-10-06 16:11:48 +0200 | [diff] [blame] | 96 | |
Radek Krejci | 5fe60cc | 2015-09-01 17:14:39 +0200 | [diff] [blame] | 97 | #endif /* NC_LOG_PRIVATE_H_ */ |