Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file log.c |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 4 | * @author Michal Vasko <mvasko@cesnet.cz> |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 5 | * @brief Logger routines implementations |
| 6 | * |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 7 | * Copyright (c) 2015 - 2022 CESNET, z.s.p.o. |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 8 | * |
| 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 |
| 12 | * |
| 13 | * https://opensource.org/licenses/BSD-3-Clause |
| 14 | */ |
| 15 | |
Christian Hopps | 32874e1 | 2021-05-01 09:43:54 -0400 | [diff] [blame] | 16 | #define _GNU_SOURCE /* asprintf, strdup */ |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 17 | |
| 18 | #include "log.h" |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 19 | |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 20 | #include <assert.h> |
Radek Krejci | c04f0a2 | 2018-09-21 15:49:45 +0200 | [diff] [blame] | 21 | #include <inttypes.h> |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 22 | #include <pthread.h> |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 23 | #include <stdarg.h> |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 24 | #include <stdint.h> |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 25 | #include <stdio.h> |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 28 | |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 29 | #include "common.h" |
Radek Krejci | aa45bda | 2020-07-20 07:43:38 +0200 | [diff] [blame] | 30 | #include "compat.h" |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 31 | #include "in_internal.h" |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 32 | #include "plugins_exts.h" |
Radek Krejci | 7711410 | 2021-03-10 15:21:57 +0100 | [diff] [blame] | 33 | #include "set.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 34 | #include "tree_data.h" |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 35 | #include "tree_data_internal.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 36 | #include "tree_schema.h" |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 37 | #include "tree_schema_internal.h" |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 38 | |
Václav Kubernát | d367ad9 | 2021-11-29 09:28:56 +0100 | [diff] [blame] | 39 | ATOMIC_T ly_ll = (uint_fast32_t)LY_LLWRN; |
| 40 | ATOMIC_T ly_log_opts = (uint_fast32_t)(LY_LOLOG | LY_LOSTORE_LAST); |
Michal Vasko | d4a6d04 | 2022-12-08 08:34:29 +0100 | [diff] [blame] | 41 | THREAD_LOCAL uint32_t *temp_ly_log_opts; |
Michal Vasko | d808561 | 2020-08-21 12:55:23 +0200 | [diff] [blame] | 42 | static ly_log_clb log_clb; |
Václav Kubernát | d367ad9 | 2021-11-29 09:28:56 +0100 | [diff] [blame] | 43 | static ATOMIC_T path_flag = 1; |
Michal Vasko | 236cbac | 2023-02-10 15:45:37 +0100 | [diff] [blame] | 44 | THREAD_LOCAL char last_msg[LY_LAST_MSG_SIZE]; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 45 | #ifndef NDEBUG |
Václav Kubernát | d367ad9 | 2021-11-29 09:28:56 +0100 | [diff] [blame] | 46 | ATOMIC_T ly_ldbg_groups = 0; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 47 | #endif |
| 48 | |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 49 | THREAD_LOCAL struct ly_log_location_s log_location = {0}; |
| 50 | |
Michal Vasko | 236cbac | 2023-02-10 15:45:37 +0100 | [diff] [blame] | 51 | LIBYANG_API_DEF const char * |
| 52 | ly_last_errmsg(void) |
| 53 | { |
| 54 | return last_msg; |
| 55 | } |
| 56 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 57 | LIBYANG_API_DEF LY_ERR |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 58 | ly_errcode(const struct ly_ctx *ctx) |
| 59 | { |
| 60 | struct ly_err_item *i; |
| 61 | |
Radek Krejci | 572ee60 | 2020-09-16 14:35:08 +0200 | [diff] [blame] | 62 | i = ly_err_last(ctx); |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 63 | if (i) { |
Radek Krejci | 572ee60 | 2020-09-16 14:35:08 +0200 | [diff] [blame] | 64 | return i->no; |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | return LY_SUCCESS; |
| 68 | } |
| 69 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 70 | LIBYANG_API_DEF LY_VECODE |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 71 | ly_vecode(const struct ly_ctx *ctx) |
| 72 | { |
| 73 | struct ly_err_item *i; |
| 74 | |
Radek Krejci | 572ee60 | 2020-09-16 14:35:08 +0200 | [diff] [blame] | 75 | i = ly_err_last(ctx); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 76 | if (i) { |
Radek Krejci | 572ee60 | 2020-09-16 14:35:08 +0200 | [diff] [blame] | 77 | return i->vecode; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | return LYVE_SUCCESS; |
| 81 | } |
| 82 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 83 | LIBYANG_API_DEF const char * |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 84 | ly_errmsg(const struct ly_ctx *ctx) |
| 85 | { |
| 86 | struct ly_err_item *i; |
| 87 | |
Michal Vasko | b3d0d6b | 2018-09-07 10:17:33 +0200 | [diff] [blame] | 88 | LY_CHECK_ARG_RET(NULL, ctx, NULL); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 89 | |
Radek Krejci | 572ee60 | 2020-09-16 14:35:08 +0200 | [diff] [blame] | 90 | i = ly_err_last(ctx); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 91 | if (i) { |
Radek Krejci | 572ee60 | 2020-09-16 14:35:08 +0200 | [diff] [blame] | 92 | return i->msg; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | return NULL; |
| 96 | } |
| 97 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 98 | LIBYANG_API_DEF const char * |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 99 | ly_errpath(const struct ly_ctx *ctx) |
| 100 | { |
| 101 | struct ly_err_item *i; |
| 102 | |
Michal Vasko | b3d0d6b | 2018-09-07 10:17:33 +0200 | [diff] [blame] | 103 | LY_CHECK_ARG_RET(NULL, ctx, NULL); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 104 | |
Radek Krejci | 572ee60 | 2020-09-16 14:35:08 +0200 | [diff] [blame] | 105 | i = ly_err_last(ctx); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 106 | if (i) { |
Radek Krejci | 572ee60 | 2020-09-16 14:35:08 +0200 | [diff] [blame] | 107 | return i->path; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | return NULL; |
| 111 | } |
| 112 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 113 | LIBYANG_API_DEF const char * |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 114 | ly_errapptag(const struct ly_ctx *ctx) |
| 115 | { |
| 116 | struct ly_err_item *i; |
| 117 | |
Michal Vasko | b3d0d6b | 2018-09-07 10:17:33 +0200 | [diff] [blame] | 118 | LY_CHECK_ARG_RET(NULL, ctx, NULL); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 119 | |
Radek Krejci | 572ee60 | 2020-09-16 14:35:08 +0200 | [diff] [blame] | 120 | i = ly_err_last(ctx); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 121 | if (i) { |
Radek Krejci | 572ee60 | 2020-09-16 14:35:08 +0200 | [diff] [blame] | 122 | return i->apptag; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | return NULL; |
| 126 | } |
| 127 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 128 | LIBYANG_API_DEF LY_ERR |
aPiecek | 6d61855 | 2021-06-18 10:02:59 +0200 | [diff] [blame] | 129 | ly_err_new(struct ly_err_item **err, LY_ERR ecode, LY_VECODE vecode, char *path, char *apptag, const char *err_format, ...) |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 130 | { |
Radek Krejci | db0ee02 | 2021-03-15 16:53:44 +0100 | [diff] [blame] | 131 | char *msg = NULL; |
| 132 | struct ly_err_item *e; |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 133 | |
Radek Krejci | d43298b | 2021-03-25 16:17:15 +0100 | [diff] [blame] | 134 | if (!err || (ecode == LY_SUCCESS)) { |
Radek Krejci | db0ee02 | 2021-03-15 16:53:44 +0100 | [diff] [blame] | 135 | /* nothing to do */ |
| 136 | return ecode; |
| 137 | } |
| 138 | |
| 139 | e = malloc(sizeof *e); |
| 140 | LY_CHECK_ERR_RET(!e, LOGMEM(NULL), LY_EMEM); |
| 141 | e->prev = (*err) ? (*err)->prev : e; |
| 142 | e->next = NULL; |
| 143 | if (*err) { |
| 144 | (*err)->prev->next = e; |
| 145 | } |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 146 | |
| 147 | /* fill in the information */ |
Radek Krejci | db0ee02 | 2021-03-15 16:53:44 +0100 | [diff] [blame] | 148 | e->level = LY_LLERR; |
| 149 | e->no = ecode; |
| 150 | e->vecode = vecode; |
| 151 | e->path = path; |
| 152 | e->apptag = apptag; |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 153 | |
aPiecek | 6d61855 | 2021-06-18 10:02:59 +0200 | [diff] [blame] | 154 | if (err_format) { |
Radek Krejci | db0ee02 | 2021-03-15 16:53:44 +0100 | [diff] [blame] | 155 | va_list print_args; |
| 156 | |
aPiecek | 6d61855 | 2021-06-18 10:02:59 +0200 | [diff] [blame] | 157 | va_start(print_args, err_format); |
Radek Krejci | db0ee02 | 2021-03-15 16:53:44 +0100 | [diff] [blame] | 158 | |
aPiecek | 6d61855 | 2021-06-18 10:02:59 +0200 | [diff] [blame] | 159 | if (vasprintf(&msg, err_format, print_args) == -1) { |
| 160 | /* we don't have anything more to do, just set msg to NULL to avoid undefined content, |
Radek Krejci | db0ee02 | 2021-03-15 16:53:44 +0100 | [diff] [blame] | 161 | * still keep the information about the original error instead of LY_EMEM or other printf's error */ |
| 162 | msg = NULL; |
| 163 | } |
| 164 | |
| 165 | va_end(print_args); |
| 166 | } |
| 167 | e->msg = msg; |
| 168 | |
| 169 | if (!(*err)) { |
| 170 | *err = e; |
| 171 | } |
| 172 | |
| 173 | return e->no; |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 174 | } |
| 175 | |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 176 | /** |
| 177 | * @brief Get error record from error hash table of a context for the current thread. |
| 178 | * |
| 179 | * @param[in] ctx Context to use. |
| 180 | * @return Thread error record, if any. |
| 181 | */ |
| 182 | static struct ly_ctx_err_rec * |
| 183 | ly_err_get_rec(const struct ly_ctx *ctx) |
| 184 | { |
| 185 | struct ly_ctx_err_rec rec, *match = NULL; |
| 186 | |
| 187 | /* prepare record */ |
| 188 | rec.tid = pthread_self(); |
| 189 | |
| 190 | /* get the pointer to the matching record */ |
| 191 | lyht_find(ctx->err_ht, &rec, dict_hash((void *)&rec.tid, sizeof rec.tid), (void **)&match); |
| 192 | |
| 193 | return match; |
| 194 | } |
| 195 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 196 | LIBYANG_API_DEF struct ly_err_item * |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 197 | ly_err_first(const struct ly_ctx *ctx) |
| 198 | { |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 199 | struct ly_ctx_err_rec *rec; |
| 200 | |
Michal Vasko | b3d0d6b | 2018-09-07 10:17:33 +0200 | [diff] [blame] | 201 | LY_CHECK_ARG_RET(NULL, ctx, NULL); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 202 | |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 203 | /* get the pointer to the matching record */ |
| 204 | rec = ly_err_get_rec(ctx); |
| 205 | |
| 206 | return rec ? rec->err : NULL; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 207 | } |
| 208 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 209 | LIBYANG_API_DEF struct ly_err_item * |
Radek Krejci | 572ee60 | 2020-09-16 14:35:08 +0200 | [diff] [blame] | 210 | ly_err_last(const struct ly_ctx *ctx) |
| 211 | { |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 212 | struct ly_ctx_err_rec *rec; |
Radek Krejci | 572ee60 | 2020-09-16 14:35:08 +0200 | [diff] [blame] | 213 | |
| 214 | LY_CHECK_ARG_RET(NULL, ctx, NULL); |
| 215 | |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 216 | /* get the pointer to the matching record */ |
| 217 | if (!(rec = ly_err_get_rec(ctx))) { |
| 218 | return NULL; |
| 219 | } |
| 220 | |
| 221 | return rec->err ? rec->err->prev : NULL; |
Radek Krejci | 572ee60 | 2020-09-16 14:35:08 +0200 | [diff] [blame] | 222 | } |
| 223 | |
Michal Vasko | 9dbb91d | 2023-01-30 13:59:22 +0100 | [diff] [blame] | 224 | void |
| 225 | ly_err_move(struct ly_ctx *src_ctx, struct ly_ctx *trg_ctx) |
| 226 | { |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 227 | struct ly_ctx_err_rec *rec; |
| 228 | struct ly_err_item *err = NULL; |
Michal Vasko | 9dbb91d | 2023-01-30 13:59:22 +0100 | [diff] [blame] | 229 | |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 230 | /* get and remove the errors from src */ |
| 231 | rec = ly_err_get_rec(src_ctx); |
| 232 | if (rec) { |
| 233 | err = rec->err; |
| 234 | rec->err = NULL; |
| 235 | } |
Michal Vasko | 9dbb91d | 2023-01-30 13:59:22 +0100 | [diff] [blame] | 236 | |
| 237 | /* set them for trg */ |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 238 | rec = ly_err_get_rec(trg_ctx); |
| 239 | ly_err_free(rec->err); |
| 240 | rec->err = err; |
Michal Vasko | 9dbb91d | 2023-01-30 13:59:22 +0100 | [diff] [blame] | 241 | } |
| 242 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 243 | LIBYANG_API_DEF void |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 244 | ly_err_free(void *ptr) |
| 245 | { |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 246 | struct ly_err_item *e, *next; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 247 | |
| 248 | /* clean the error list */ |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 249 | LY_LIST_FOR_SAFE(ptr, next, e) { |
| 250 | free(e->msg); |
| 251 | free(e->path); |
| 252 | free(e->apptag); |
| 253 | free(e); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 257 | LIBYANG_API_DEF void |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 258 | ly_err_clean(struct ly_ctx *ctx, struct ly_err_item *eitem) |
| 259 | { |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 260 | struct ly_ctx_err_rec *rec; |
| 261 | struct ly_err_item *e; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 262 | |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 263 | if (!(rec = ly_err_get_rec(ctx))) { |
| 264 | return; |
| 265 | } |
| 266 | if (rec->err == eitem) { |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 267 | eitem = NULL; |
| 268 | } |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 269 | |
| 270 | if (!eitem) { |
| 271 | /* free all err */ |
| 272 | ly_err_free(rec->err); |
| 273 | rec->err = NULL; |
| 274 | } else { |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 275 | /* disconnect the error */ |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 276 | for (e = rec->err; e && (e->next != eitem); e = e->next) {} |
| 277 | assert(e); |
| 278 | e->next = NULL; |
| 279 | rec->err->prev = e; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 280 | /* free this err and newer */ |
| 281 | ly_err_free(eitem); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 285 | LIBYANG_API_DEF LY_LOG_LEVEL |
Radek Krejci | 52b6d51 | 2020-10-12 12:33:17 +0200 | [diff] [blame] | 286 | ly_log_level(LY_LOG_LEVEL level) |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 287 | { |
Václav Kubernát | d367ad9 | 2021-11-29 09:28:56 +0100 | [diff] [blame] | 288 | LY_LOG_LEVEL prev = ATOMIC_LOAD_RELAXED(ly_ll); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 289 | |
Václav Kubernát | d367ad9 | 2021-11-29 09:28:56 +0100 | [diff] [blame] | 290 | ATOMIC_STORE_RELAXED(ly_ll, level); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 291 | return prev; |
| 292 | } |
| 293 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 294 | LIBYANG_API_DEF uint32_t |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 295 | ly_log_options(uint32_t opts) |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 296 | { |
Václav Kubernát | d367ad9 | 2021-11-29 09:28:56 +0100 | [diff] [blame] | 297 | uint32_t prev = ATOMIC_LOAD_RELAXED(ly_log_opts); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 298 | |
Václav Kubernát | d367ad9 | 2021-11-29 09:28:56 +0100 | [diff] [blame] | 299 | ATOMIC_STORE_RELAXED(ly_log_opts, opts); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 300 | return prev; |
| 301 | } |
| 302 | |
Michal Vasko | d4a6d04 | 2022-12-08 08:34:29 +0100 | [diff] [blame] | 303 | LIBYANG_API_DEF void |
| 304 | ly_temp_log_options(uint32_t *opts) |
| 305 | { |
| 306 | temp_ly_log_opts = opts; |
| 307 | } |
| 308 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 309 | LIBYANG_API_DEF uint32_t |
Radek Krejci | 68433c9 | 2020-10-12 17:03:55 +0200 | [diff] [blame] | 310 | ly_log_dbg_groups(uint32_t dbg_groups) |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 311 | { |
| 312 | #ifndef NDEBUG |
Václav Kubernát | d367ad9 | 2021-11-29 09:28:56 +0100 | [diff] [blame] | 313 | uint32_t prev = ATOMIC_LOAD_RELAXED(ly_ldbg_groups); |
Radek Krejci | ebdaed0 | 2020-11-09 13:05:06 +0100 | [diff] [blame] | 314 | |
Václav Kubernát | d367ad9 | 2021-11-29 09:28:56 +0100 | [diff] [blame] | 315 | ATOMIC_STORE_RELAXED(ly_ldbg_groups, dbg_groups); |
Radek Krejci | ebdaed0 | 2020-11-09 13:05:06 +0100 | [diff] [blame] | 316 | return prev; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 317 | #else |
| 318 | (void)dbg_groups; |
Radek Krejci | ebdaed0 | 2020-11-09 13:05:06 +0100 | [diff] [blame] | 319 | return 0; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 320 | #endif |
| 321 | } |
| 322 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 323 | LIBYANG_API_DEF void |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 324 | ly_set_log_clb(ly_log_clb clb, ly_bool path) |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 325 | { |
Michal Vasko | d808561 | 2020-08-21 12:55:23 +0200 | [diff] [blame] | 326 | log_clb = clb; |
Václav Kubernát | d367ad9 | 2021-11-29 09:28:56 +0100 | [diff] [blame] | 327 | ATOMIC_STORE_RELAXED(path_flag, path); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 328 | } |
| 329 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 330 | LIBYANG_API_DEF ly_log_clb |
Michal Vasko | d808561 | 2020-08-21 12:55:23 +0200 | [diff] [blame] | 331 | ly_get_log_clb(void) |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 332 | { |
Michal Vasko | d808561 | 2020-08-21 12:55:23 +0200 | [diff] [blame] | 333 | return log_clb; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 334 | } |
| 335 | |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 336 | void |
Michal Vasko | 59e69e7 | 2022-02-18 09:18:21 +0100 | [diff] [blame] | 337 | ly_log_location(const struct lysc_node *scnode, const struct lyd_node *dnode, const char *path, const struct ly_in *in, |
Michal Vasko | f8ebf13 | 2022-11-21 14:06:48 +0100 | [diff] [blame] | 338 | uint64_t line) |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 339 | { |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 340 | if (scnode) { |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 341 | ly_set_add(&log_location.scnodes, (void *)scnode, 1, NULL); |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 342 | } |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 343 | if (dnode) { |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 344 | ly_set_add(&log_location.dnodes, (void *)dnode, 1, NULL); |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 345 | } |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 346 | if (path) { |
| 347 | char *s = strdup(path); |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 348 | |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 349 | LY_CHECK_ERR_RET(!s, LOGMEM(NULL), ); |
| 350 | ly_set_add(&log_location.paths, s, 1, NULL); |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 351 | } |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 352 | if (in) { |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 353 | ly_set_add(&log_location.inputs, (void *)in, 1, NULL); |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 354 | } |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 355 | if (line) { |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 356 | log_location.line = line; |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 357 | } |
| 358 | } |
| 359 | |
| 360 | void |
Michal Vasko | 59e69e7 | 2022-02-18 09:18:21 +0100 | [diff] [blame] | 361 | ly_log_location_revert(uint32_t scnode_steps, uint32_t dnode_steps, uint32_t path_steps, uint32_t in_steps) |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 362 | { |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 363 | for (uint32_t i = scnode_steps; i && log_location.scnodes.count; i--) { |
| 364 | log_location.scnodes.count--; |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 365 | } |
| 366 | |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 367 | for (uint32_t i = dnode_steps; i && log_location.dnodes.count; i--) { |
| 368 | log_location.dnodes.count--; |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 369 | } |
| 370 | |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 371 | for (uint32_t i = path_steps; i && log_location.paths.count; i--) { |
| 372 | ly_set_rm_index(&log_location.paths, log_location.paths.count - 1, free); |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 373 | } |
| 374 | |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 375 | for (uint32_t i = in_steps; i && log_location.inputs.count; i--) { |
| 376 | log_location.inputs.count--; |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 377 | } |
| 378 | |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 379 | /* deallocate the empty sets */ |
| 380 | if (scnode_steps && !log_location.scnodes.count) { |
| 381 | ly_set_erase(&log_location.scnodes, NULL); |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 382 | } |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 383 | if (dnode_steps && !log_location.dnodes.count) { |
| 384 | ly_set_erase(&log_location.dnodes, NULL); |
| 385 | } |
| 386 | if (path_steps && !log_location.paths.count) { |
| 387 | ly_set_erase(&log_location.paths, free); |
| 388 | } |
| 389 | if (in_steps && !log_location.inputs.count) { |
| 390 | ly_set_erase(&log_location.inputs, NULL); |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 391 | } |
| 392 | } |
| 393 | |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 394 | /** |
| 395 | * @brief Store generated error in a context. |
| 396 | * |
| 397 | * @param[in] ctx Context to use. |
| 398 | * @param[in] level Message log level. |
| 399 | * @param[in] no Error number. |
| 400 | * @param[in] vecode Error validation error code. |
| 401 | * @param[in] msg Error message, always spent. |
| 402 | * @param[in] path Error path, always spent. |
| 403 | * @param[in] apptag Error app tag, always spent. |
| 404 | * @return LY_ERR value. |
| 405 | */ |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 406 | static LY_ERR |
| 407 | log_store(const struct ly_ctx *ctx, LY_LOG_LEVEL level, LY_ERR no, LY_VECODE vecode, char *msg, char *path, char *apptag) |
| 408 | { |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 409 | struct ly_ctx_err_rec *rec, new; |
| 410 | struct ly_err_item *e, *last; |
| 411 | LY_ERR r; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 412 | |
| 413 | assert(ctx && (level < LY_LLVRB)); |
| 414 | |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 415 | if (!(rec = ly_err_get_rec(ctx))) { |
| 416 | /* insert a new record */ |
| 417 | new.err = NULL; |
| 418 | new.tid = pthread_self(); |
Michal Vasko | 48c00d8 | 2023-03-30 11:59:45 +0200 | [diff] [blame] | 419 | |
| 420 | /* reuse lock */ |
| 421 | /* LOCK */ |
| 422 | pthread_mutex_lock((pthread_mutex_t *)&ctx->lyb_hash_lock); |
| 423 | |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 424 | r = lyht_insert(ctx->err_ht, &new, dict_hash((void *)&new.tid, sizeof new.tid), (void **)&rec); |
Michal Vasko | 48c00d8 | 2023-03-30 11:59:45 +0200 | [diff] [blame] | 425 | |
| 426 | /* UNLOCK */ |
| 427 | pthread_mutex_unlock((pthread_mutex_t *)&ctx->lyb_hash_lock); |
| 428 | |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 429 | if (r) { |
| 430 | /* should never happen */ |
| 431 | return r; |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | e = rec->err; |
| 436 | if (!e) { |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 437 | /* if we are only to fill in path, there must have been an error stored */ |
| 438 | assert(msg); |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 439 | e = malloc(sizeof *e); |
| 440 | LY_CHECK_GOTO(!e, mem_fail); |
| 441 | e->prev = e; |
| 442 | e->next = NULL; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 443 | |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 444 | rec->err = e; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 445 | } else if (!msg) { |
| 446 | /* only filling the path */ |
| 447 | assert(path); |
| 448 | |
| 449 | /* find last error */ |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 450 | e = e->prev; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 451 | do { |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 452 | if (e->level == LY_LLERR) { |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 453 | /* fill the path */ |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 454 | free(e->path); |
| 455 | e->path = path; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 456 | return LY_SUCCESS; |
| 457 | } |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 458 | e = e->prev; |
| 459 | } while (e->prev->next); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 460 | /* last error was not found */ |
| 461 | assert(0); |
Michal Vasko | d4a6d04 | 2022-12-08 08:34:29 +0100 | [diff] [blame] | 462 | } else if ((temp_ly_log_opts && ((*temp_ly_log_opts & LY_LOSTORE_LAST) == LY_LOSTORE_LAST)) || |
| 463 | (!temp_ly_log_opts && ((ATOMIC_LOAD_RELAXED(ly_log_opts) & LY_LOSTORE_LAST) == LY_LOSTORE_LAST))) { |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 464 | /* overwrite last message */ |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 465 | free(e->msg); |
| 466 | free(e->path); |
| 467 | free(e->apptag); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 468 | } else { |
| 469 | /* store new message */ |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 470 | last = e->prev; |
| 471 | e->prev = malloc(sizeof *e); |
| 472 | LY_CHECK_GOTO(!e->prev, mem_fail); |
| 473 | e = e->prev; |
| 474 | e->prev = last; |
| 475 | e->next = NULL; |
| 476 | last->next = e; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | /* fill in the information */ |
Michal Vasko | 88ccd58 | 2023-03-30 11:50:57 +0200 | [diff] [blame] | 480 | e->level = level; |
| 481 | e->no = no; |
| 482 | e->vecode = vecode; |
| 483 | e->msg = msg; |
| 484 | e->path = path; |
| 485 | e->apptag = apptag; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 486 | return LY_SUCCESS; |
| 487 | |
| 488 | mem_fail: |
| 489 | LOGMEM(NULL); |
| 490 | free(msg); |
| 491 | free(path); |
| 492 | free(apptag); |
| 493 | return LY_EMEM; |
| 494 | } |
| 495 | |
| 496 | static void |
Michal Vasko | e9391c7 | 2021-10-05 10:04:56 +0200 | [diff] [blame] | 497 | log_vprintf(const struct ly_ctx *ctx, LY_LOG_LEVEL level, LY_ERR no, LY_VECODE vecode, char *path, const char *apptag, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 498 | const char *format, va_list args) |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 499 | { |
| 500 | char *msg = NULL; |
Michal Vasko | d4a6d04 | 2022-12-08 08:34:29 +0100 | [diff] [blame] | 501 | ly_bool free_strs, lolog, lostore; |
| 502 | |
| 503 | /* learn effective logger options */ |
| 504 | if (temp_ly_log_opts) { |
| 505 | lolog = *temp_ly_log_opts & LY_LOLOG; |
| 506 | lostore = *temp_ly_log_opts & LY_LOSTORE; |
| 507 | } else { |
| 508 | lolog = ATOMIC_LOAD_RELAXED(ly_log_opts) & LY_LOLOG; |
| 509 | lostore = ATOMIC_LOAD_RELAXED(ly_log_opts) & LY_LOSTORE; |
| 510 | } |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 511 | |
Václav Kubernát | d367ad9 | 2021-11-29 09:28:56 +0100 | [diff] [blame] | 512 | if (level > ATOMIC_LOAD_RELAXED(ly_ll)) { |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 513 | /* do not print or store the message */ |
| 514 | free(path); |
| 515 | return; |
| 516 | } |
| 517 | |
Michal Vasko | 5a01692 | 2021-05-07 08:19:15 +0200 | [diff] [blame] | 518 | if (no == LY_EMEM) { |
| 519 | /* just print it, anything else would most likely fail anyway */ |
Michal Vasko | d4a6d04 | 2022-12-08 08:34:29 +0100 | [diff] [blame] | 520 | if (lolog) { |
Michal Vasko | 5a01692 | 2021-05-07 08:19:15 +0200 | [diff] [blame] | 521 | if (log_clb) { |
| 522 | log_clb(level, LY_EMEM_MSG, path); |
| 523 | } else { |
| 524 | fprintf(stderr, "libyang[%d]: ", level); |
| 525 | vfprintf(stderr, format, args); |
| 526 | if (path) { |
| 527 | fprintf(stderr, " (path: %s)\n", path); |
| 528 | } else { |
| 529 | fprintf(stderr, "\n"); |
| 530 | } |
| 531 | } |
| 532 | } |
| 533 | free(path); |
| 534 | return; |
| 535 | } |
| 536 | |
Michal Vasko | 236cbac | 2023-02-10 15:45:37 +0100 | [diff] [blame] | 537 | /* print into a single message */ |
| 538 | if (vasprintf(&msg, format, args) == -1) { |
| 539 | LOGMEM(ctx); |
| 540 | free(path); |
| 541 | return; |
| 542 | } |
| 543 | |
| 544 | /* store as the last message */ |
| 545 | strncpy(last_msg, msg, LY_LAST_MSG_SIZE - 1); |
| 546 | |
| 547 | /* store the error/warning in the context (if we need to store errors internally, it does not matter what are |
| 548 | * the user log options) */ |
Michal Vasko | d4a6d04 | 2022-12-08 08:34:29 +0100 | [diff] [blame] | 549 | if ((level < LY_LLVRB) && ctx && lostore) { |
Radek Krejci | c9e64a6 | 2020-09-18 20:08:12 +0200 | [diff] [blame] | 550 | if (((no & ~LY_EPLUGIN) == LY_EVALID) && (vecode == LYVE_SUCCESS)) { |
| 551 | /* assume we are inheriting the error, so inherit vecode as well */ |
| 552 | vecode = ly_vecode(ctx); |
| 553 | } |
Michal Vasko | e9391c7 | 2021-10-05 10:04:56 +0200 | [diff] [blame] | 554 | if (log_store(ctx, level, no, vecode, msg, path, apptag ? strdup(apptag) : NULL)) { |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 555 | return; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 556 | } |
| 557 | free_strs = 0; |
| 558 | } else { |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 559 | free_strs = 1; |
| 560 | } |
| 561 | |
| 562 | /* if we are only storing errors internally, never print the message (yet) */ |
Michal Vasko | d4a6d04 | 2022-12-08 08:34:29 +0100 | [diff] [blame] | 563 | if (lolog) { |
Michal Vasko | d808561 | 2020-08-21 12:55:23 +0200 | [diff] [blame] | 564 | if (log_clb) { |
| 565 | log_clb(level, msg, path); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 566 | } else { |
| 567 | fprintf(stderr, "libyang[%d]: %s%s", level, msg, path ? " " : "\n"); |
| 568 | if (path) { |
| 569 | fprintf(stderr, "(path: %s)\n", path); |
| 570 | } |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | if (free_strs) { |
| 575 | free(path); |
| 576 | free(msg); |
| 577 | } |
| 578 | } |
| 579 | |
Radek Krejci | 4ab6156 | 2018-09-05 15:00:37 +0200 | [diff] [blame] | 580 | #ifndef NDEBUG |
| 581 | |
| 582 | void |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 583 | ly_log_dbg(uint32_t group, const char *format, ...) |
Radek Krejci | 4ab6156 | 2018-09-05 15:00:37 +0200 | [diff] [blame] | 584 | { |
| 585 | char *dbg_format; |
| 586 | const char *str_group; |
| 587 | va_list ap; |
| 588 | |
Václav Kubernát | d367ad9 | 2021-11-29 09:28:56 +0100 | [diff] [blame] | 589 | if (!(ATOMIC_LOAD_RELAXED(ly_ldbg_groups) & group)) { |
Radek Krejci | 4ab6156 | 2018-09-05 15:00:37 +0200 | [diff] [blame] | 590 | return; |
| 591 | } |
| 592 | |
| 593 | switch (group) { |
| 594 | case LY_LDGDICT: |
| 595 | str_group = "DICT"; |
| 596 | break; |
Radek Krejci | 4ab6156 | 2018-09-05 15:00:37 +0200 | [diff] [blame] | 597 | case LY_LDGXPATH: |
| 598 | str_group = "XPATH"; |
| 599 | break; |
Michal Vasko | e558f79 | 2021-07-28 08:20:15 +0200 | [diff] [blame] | 600 | case LY_LDGDEPSETS: |
| 601 | str_group = "DEPSETS"; |
| 602 | break; |
Radek Krejci | 4ab6156 | 2018-09-05 15:00:37 +0200 | [diff] [blame] | 603 | default: |
| 604 | LOGINT(NULL); |
| 605 | return; |
| 606 | } |
| 607 | |
| 608 | if (asprintf(&dbg_format, "%s: %s", str_group, format) == -1) { |
| 609 | LOGMEM(NULL); |
| 610 | return; |
| 611 | } |
| 612 | |
| 613 | va_start(ap, format); |
Michal Vasko | e9391c7 | 2021-10-05 10:04:56 +0200 | [diff] [blame] | 614 | log_vprintf(NULL, LY_LLDBG, 0, 0, NULL, NULL, dbg_format, ap); |
Radek Krejci | 4ab6156 | 2018-09-05 15:00:37 +0200 | [diff] [blame] | 615 | va_end(ap); |
| 616 | } |
| 617 | |
| 618 | #endif |
| 619 | |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 620 | void |
| 621 | ly_log(const struct ly_ctx *ctx, LY_LOG_LEVEL level, LY_ERR no, const char *format, ...) |
| 622 | { |
| 623 | va_list ap; |
| 624 | |
| 625 | va_start(ap, format); |
Michal Vasko | e9391c7 | 2021-10-05 10:04:56 +0200 | [diff] [blame] | 626 | log_vprintf(ctx, level, no, 0, NULL, NULL, format, ap); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 627 | va_end(ap); |
| 628 | } |
| 629 | |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 630 | /** |
| 631 | * @brief Append a schema node name to a generated data path, only if it fits. |
| 632 | * |
| 633 | * @param[in,out] str Generated path to update. |
| 634 | * @param[in] snode Schema node to append. |
| 635 | * @param[in] parent Last printed data node. |
| 636 | * @return LY_ERR value. |
| 637 | */ |
| 638 | static LY_ERR |
| 639 | ly_vlog_build_path_append(char **str, const struct lysc_node *snode, const struct lyd_node *parent) |
| 640 | { |
| 641 | const struct lys_module *mod, *prev_mod; |
| 642 | uint32_t len, new_len; |
| 643 | void *mem; |
| 644 | |
| 645 | if (snode->nodetype & (LYS_CHOICE | LYS_CASE)) { |
| 646 | /* schema-only node */ |
| 647 | return LY_SUCCESS; |
| 648 | } else if (lysc_data_parent(snode) != parent->schema) { |
| 649 | /* not a direct descendant node */ |
| 650 | return LY_SUCCESS; |
| 651 | } |
| 652 | |
| 653 | /* get module to print, if any */ |
| 654 | mod = snode->module; |
| 655 | prev_mod = (parent->schema) ? parent->schema->module : lyd_owner_module(parent); |
| 656 | if (prev_mod == mod) { |
| 657 | mod = NULL; |
| 658 | } |
| 659 | |
| 660 | /* realloc string */ |
| 661 | len = strlen(*str); |
| 662 | new_len = len + 1 + (mod ? strlen(mod->name) + 1 : 0) + strlen(snode->name); |
| 663 | mem = realloc(*str, new_len + 1); |
| 664 | LY_CHECK_ERR_RET(!mem, LOGMEM(LYD_CTX(parent)), LY_EMEM); |
| 665 | *str = mem; |
| 666 | |
| 667 | /* print the last schema node */ |
| 668 | sprintf(*str + len, "/%s%s%s", mod ? mod->name : "", mod ? ":" : "", snode->name); |
| 669 | return LY_SUCCESS; |
| 670 | } |
| 671 | |
| 672 | /** |
| 673 | * @brief Build log path from the stored log location information. |
| 674 | * |
| 675 | * @param[in] ctx Context to use. |
| 676 | * @param[out] path Generated log path. |
| 677 | * @return LY_ERR value. |
| 678 | */ |
Radek Krejci | 94aa994 | 2018-09-07 17:12:17 +0200 | [diff] [blame] | 679 | static LY_ERR |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 680 | ly_vlog_build_path(const struct ly_ctx *ctx, char **path) |
Radek Krejci | 94aa994 | 2018-09-07 17:12:17 +0200 | [diff] [blame] | 681 | { |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 682 | int r; |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 683 | char *str = NULL, *prev = NULL; |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 684 | const struct lyd_node *dnode; |
Radek Krejci | cb3e647 | 2021-01-06 08:19:01 +0100 | [diff] [blame] | 685 | |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 686 | *path = NULL; |
Radek Krejci | 94aa994 | 2018-09-07 17:12:17 +0200 | [diff] [blame] | 687 | |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 688 | if (log_location.paths.count && ((const char *)(log_location.paths.objs[log_location.paths.count - 1]))[0]) { |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 689 | /* simply get what is in the provided path string */ |
Michal Vasko | 6727c68 | 2023-02-17 10:40:26 +0100 | [diff] [blame] | 690 | r = asprintf(path, "Path \"%s\".", (const char *)log_location.paths.objs[log_location.paths.count - 1]); |
| 691 | LY_CHECK_ERR_RET(r == -1, LOGMEM(ctx), LY_EMEM); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 692 | } else { |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 693 | /* data/schema node */ |
| 694 | if (log_location.dnodes.count) { |
| 695 | dnode = log_location.dnodes.objs[log_location.dnodes.count - 1]; |
Michal Vasko | a4dfb3c | 2022-10-25 14:59:31 +0200 | [diff] [blame] | 696 | if (dnode->parent || !lysc_data_parent(dnode->schema)) { |
| 697 | /* data node with all of its parents */ |
| 698 | str = lyd_path(log_location.dnodes.objs[log_location.dnodes.count - 1], LYD_PATH_STD, NULL, 0); |
| 699 | LY_CHECK_ERR_RET(!str, LOGMEM(ctx), LY_EMEM); |
| 700 | } else { |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 701 | /* data parsers put all the parent nodes in the set, but they are not connected */ |
| 702 | str = lyd_path_set(&log_location.dnodes, LYD_PATH_STD); |
Michal Vasko | 3e65ee3 | 2022-10-21 10:09:51 +0200 | [diff] [blame] | 703 | LY_CHECK_ERR_RET(!str, LOGMEM(ctx), LY_EMEM); |
Michal Vasko | a4dfb3c | 2022-10-25 14:59:31 +0200 | [diff] [blame] | 704 | } |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 705 | |
Michal Vasko | a4dfb3c | 2022-10-25 14:59:31 +0200 | [diff] [blame] | 706 | /* sometimes the last node is not created yet and we only have the schema node */ |
| 707 | if (log_location.scnodes.count) { |
| 708 | ly_vlog_build_path_append(&str, log_location.scnodes.objs[log_location.scnodes.count - 1], dnode); |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 709 | } |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 710 | |
| 711 | r = asprintf(path, "Data location \"%s\"", str); |
| 712 | free(str); |
| 713 | LY_CHECK_ERR_RET(r == -1, LOGMEM(ctx), LY_EMEM); |
| 714 | } else if (log_location.scnodes.count) { |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 715 | str = lysc_path(log_location.scnodes.objs[log_location.scnodes.count - 1], LYSC_PATH_LOG, NULL, 0); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 716 | LY_CHECK_ERR_RET(!str, LOGMEM(ctx), LY_EMEM); |
| 717 | |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 718 | r = asprintf(path, "Schema location \"%s\"", str); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 719 | free(str); |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 720 | LY_CHECK_ERR_RET(r == -1, LOGMEM(ctx), LY_EMEM); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 721 | } |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 722 | |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 723 | /* line */ |
| 724 | prev = *path; |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 725 | if (log_location.line) { |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 726 | r = asprintf(path, "%s%sine number %" PRIu64, prev ? prev : "", prev ? ", l" : "L", log_location.line); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 727 | free(prev); |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 728 | LY_CHECK_ERR_RET(r == -1, LOGMEM(ctx), LY_EMEM); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 729 | |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 730 | log_location.line = 0; |
| 731 | } else if (log_location.inputs.count) { |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 732 | r = asprintf(path, "%s%sine number %" PRIu64, prev ? prev : "", prev ? ", l" : "L", |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 733 | ((struct ly_in *)log_location.inputs.objs[log_location.inputs.count - 1])->line); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 734 | free(prev); |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 735 | LY_CHECK_ERR_RET(r == -1, LOGMEM(ctx), LY_EMEM); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | if (*path) { |
| 739 | prev = *path; |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 740 | r = asprintf(path, "%s.", prev); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 741 | free(prev); |
Michal Vasko | dbf3e65 | 2022-10-21 08:46:25 +0200 | [diff] [blame] | 742 | LY_CHECK_ERR_RET(r == -1, LOGMEM(ctx), LY_EMEM); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 743 | } |
Radek Krejci | 94aa994 | 2018-09-07 17:12:17 +0200 | [diff] [blame] | 744 | } |
| 745 | |
Radek Krejci | 94aa994 | 2018-09-07 17:12:17 +0200 | [diff] [blame] | 746 | return LY_SUCCESS; |
| 747 | } |
| 748 | |
| 749 | void |
Michal Vasko | e9391c7 | 2021-10-05 10:04:56 +0200 | [diff] [blame] | 750 | ly_vlog(const struct ly_ctx *ctx, const char *apptag, LY_VECODE code, const char *format, ...) |
Radek Krejci | 94aa994 | 2018-09-07 17:12:17 +0200 | [diff] [blame] | 751 | { |
| 752 | va_list ap; |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 753 | char *path = NULL; |
Radek Krejci | 94aa994 | 2018-09-07 17:12:17 +0200 | [diff] [blame] | 754 | |
Václav Kubernát | d367ad9 | 2021-11-29 09:28:56 +0100 | [diff] [blame] | 755 | if (ATOMIC_LOAD_RELAXED(path_flag) && ctx) { |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 756 | ly_vlog_build_path(ctx, &path); |
Radek Krejci | 94aa994 | 2018-09-07 17:12:17 +0200 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | va_start(ap, format); |
Michal Vasko | e9391c7 | 2021-10-05 10:04:56 +0200 | [diff] [blame] | 760 | log_vprintf(ctx, LY_LLERR, LY_EVALID, code, path, apptag, format, ap); |
Radek Krejci | 94aa994 | 2018-09-07 17:12:17 +0200 | [diff] [blame] | 761 | /* path is spent and should not be freed! */ |
| 762 | va_end(ap); |
| 763 | } |
| 764 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 765 | /** |
| 766 | * @brief Print a log message from an extension plugin callback. |
| 767 | * |
| 768 | * @param[in] ctx libyang context to store the error record. If not provided, the error is just printed. |
| 769 | * @param[in] plugin_name Name of the plugin generating the message. |
| 770 | * @param[in] level Log message level (error, warning, etc.) |
| 771 | * @param[in] err_no Error type code. |
Michal Vasko | 6727c68 | 2023-02-17 10:40:26 +0100 | [diff] [blame] | 772 | * @param[in] path Optional path of the error, used if set. |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 773 | * @param[in] format Format string to print. |
| 774 | * @param[in] ap Var arg list for @p format. |
| 775 | */ |
| 776 | static void |
Michal Vasko | 6727c68 | 2023-02-17 10:40:26 +0100 | [diff] [blame] | 777 | ly_ext_log(const struct ly_ctx *ctx, const char *plugin_name, LY_LOG_LEVEL level, LY_ERR err_no, char *path, |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 778 | const char *format, va_list ap) |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 779 | { |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 780 | char *plugin_msg; |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 781 | |
Václav Kubernát | d367ad9 | 2021-11-29 09:28:56 +0100 | [diff] [blame] | 782 | if (ATOMIC_LOAD_RELAXED(ly_ll) < level) { |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 783 | return; |
| 784 | } |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 785 | if (asprintf(&plugin_msg, "Ext plugin \"%s\": %s", plugin_name, format) == -1) { |
| 786 | LOGMEM(ctx); |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 787 | return; |
| 788 | } |
| 789 | |
Michal Vasko | 6727c68 | 2023-02-17 10:40:26 +0100 | [diff] [blame] | 790 | log_vprintf(ctx, level, (level == LY_LLERR ? LY_EPLUGIN : 0) | err_no, LYVE_OTHER, path, NULL, plugin_msg, ap); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 791 | free(plugin_msg); |
| 792 | } |
| 793 | |
| 794 | LIBYANG_API_DEF void |
| 795 | lyplg_ext_parse_log(const struct lysp_ctx *pctx, const struct lysp_ext_instance *ext, LY_LOG_LEVEL level, LY_ERR err_no, |
| 796 | const char *format, ...) |
| 797 | { |
| 798 | va_list ap; |
| 799 | char *path = NULL; |
| 800 | |
| 801 | if (ATOMIC_LOAD_RELAXED(path_flag)) { |
| 802 | ly_vlog_build_path(PARSER_CTX(pctx), &path); |
| 803 | } |
| 804 | |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 805 | va_start(ap, format); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 806 | ly_ext_log(PARSER_CTX(pctx), ext->record->plugin.id, level, err_no, path, format, ap); |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 807 | va_end(ap); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | LIBYANG_API_DEF void |
| 811 | lyplg_ext_compile_log(const struct lysc_ctx *cctx, const struct lysc_ext_instance *ext, LY_LOG_LEVEL level, LY_ERR err_no, |
| 812 | const char *format, ...) |
| 813 | { |
| 814 | va_list ap; |
Michal Vasko | 6727c68 | 2023-02-17 10:40:26 +0100 | [diff] [blame] | 815 | char *path = NULL; |
| 816 | |
| 817 | if (cctx && (asprintf(&path, "Path \"%s\".", cctx->path) == -1)) { |
| 818 | LOGMEM(cctx->ctx); |
| 819 | return; |
| 820 | } |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 821 | |
| 822 | va_start(ap, format); |
Michal Vasko | 6727c68 | 2023-02-17 10:40:26 +0100 | [diff] [blame] | 823 | ly_ext_log(ext->module->ctx, ext->def->plugin->id, level, err_no, path, format, ap); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 824 | va_end(ap); |
| 825 | } |
| 826 | |
| 827 | LIBYANG_API_DEF void |
| 828 | lyplg_ext_compile_log_path(const char *path, const struct lysc_ext_instance *ext, LY_LOG_LEVEL level, LY_ERR err_no, |
| 829 | const char *format, ...) |
| 830 | { |
| 831 | va_list ap; |
Michal Vasko | 6727c68 | 2023-02-17 10:40:26 +0100 | [diff] [blame] | 832 | char *log_path = NULL; |
| 833 | |
| 834 | if (path && (asprintf(&log_path, "Path \"%s\".", path) == -1)) { |
| 835 | LOGMEM(ext->module->ctx); |
| 836 | return; |
| 837 | } |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 838 | |
| 839 | va_start(ap, format); |
Michal Vasko | 6727c68 | 2023-02-17 10:40:26 +0100 | [diff] [blame] | 840 | ly_ext_log(ext->module->ctx, ext->def->plugin->id, level, err_no, log_path, format, ap); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 841 | va_end(ap); |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 842 | } |
| 843 | |
Michal Vasko | 177d0ed | 2020-11-23 16:43:03 +0100 | [diff] [blame] | 844 | /** |
Michal Vasko | 6727c68 | 2023-02-17 10:40:26 +0100 | [diff] [blame] | 845 | * @brief Serves only for creating ap. |
| 846 | */ |
| 847 | static void |
| 848 | _lyplg_ext_compile_log_err(const struct ly_err_item *err, const struct lysc_ext_instance *ext, ...) |
| 849 | { |
| 850 | va_list ap; |
| 851 | |
| 852 | va_start(ap, ext); |
| 853 | ly_ext_log(ext->module->ctx, ext->def->plugin->id, err->level, err->no, err->path ? strdup(err->path) : NULL, "%s", ap); |
| 854 | va_end(ap); |
| 855 | } |
| 856 | |
| 857 | LIBYANG_API_DEF void |
| 858 | lyplg_ext_compile_log_err(const struct ly_err_item *err, const struct lysc_ext_instance *ext) |
| 859 | { |
| 860 | _lyplg_ext_compile_log_err(err, ext, err->msg); |
| 861 | } |
| 862 | |
| 863 | /** |
Michal Vasko | c78a609 | 2021-05-07 15:27:35 +0200 | [diff] [blame] | 864 | * @brief Exact same functionality as ::ly_err_print() but has variable arguments so log_vprintf() can be called. |
Michal Vasko | 177d0ed | 2020-11-23 16:43:03 +0100 | [diff] [blame] | 865 | */ |
| 866 | static void |
Michal Vasko | c78a609 | 2021-05-07 15:27:35 +0200 | [diff] [blame] | 867 | _ly_err_print(const struct ly_ctx *ctx, struct ly_err_item *eitem, const char *format, ...) |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 868 | { |
Michal Vasko | 177d0ed | 2020-11-23 16:43:03 +0100 | [diff] [blame] | 869 | va_list ap; |
| 870 | char *path_dup = NULL; |
| 871 | |
| 872 | LY_CHECK_ARG_RET(ctx, eitem, ); |
| 873 | |
| 874 | if (eitem->path) { |
| 875 | /* duplicate path because it will be freed */ |
| 876 | path_dup = strdup(eitem->path); |
| 877 | LY_CHECK_ERR_RET(!path_dup, LOGMEM(ctx), ); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 878 | } |
Michal Vasko | 177d0ed | 2020-11-23 16:43:03 +0100 | [diff] [blame] | 879 | |
Michal Vasko | c78a609 | 2021-05-07 15:27:35 +0200 | [diff] [blame] | 880 | va_start(ap, format); |
Michal Vasko | e9391c7 | 2021-10-05 10:04:56 +0200 | [diff] [blame] | 881 | log_vprintf(ctx, eitem->level, eitem->no, eitem->vecode, path_dup, eitem->apptag, format, ap); |
Michal Vasko | 177d0ed | 2020-11-23 16:43:03 +0100 | [diff] [blame] | 882 | va_end(ap); |
Michal Vasko | 177d0ed | 2020-11-23 16:43:03 +0100 | [diff] [blame] | 883 | } |
| 884 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 885 | LIBYANG_API_DEF void |
Michal Vasko | 177d0ed | 2020-11-23 16:43:03 +0100 | [diff] [blame] | 886 | ly_err_print(const struct ly_ctx *ctx, struct ly_err_item *eitem) |
| 887 | { |
Michal Vasko | c78a609 | 2021-05-07 15:27:35 +0200 | [diff] [blame] | 888 | /* String ::ly_err_item.msg cannot be used directly because it may contain the % character */ |
| 889 | _ly_err_print(ctx, eitem, "%s", eitem->msg); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 890 | } |