Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file log.c |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief Logger routines implementations |
| 5 | * |
| 6 | * Copyright (c) 2015 - 2018 CESNET, z.s.p.o. |
| 7 | * |
| 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * https://opensource.org/licenses/BSD-3-Clause |
| 13 | */ |
| 14 | |
Christian Hopps | 32874e1 | 2021-05-01 09:43:54 -0400 | [diff] [blame] | 15 | #define _GNU_SOURCE /* asprintf, strdup */ |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 16 | |
| 17 | #include "log.h" |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 18 | |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 19 | #include <assert.h> |
Radek Krejci | c04f0a2 | 2018-09-21 15:49:45 +0200 | [diff] [blame] | 20 | #include <inttypes.h> |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 21 | #include <pthread.h> |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 22 | #include <stdarg.h> |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 23 | #include <stdint.h> |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 24 | #include <stdio.h> |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 27 | |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 28 | #include "common.h" |
Radek Krejci | aa45bda | 2020-07-20 07:43:38 +0200 | [diff] [blame] | 29 | #include "compat.h" |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 30 | #include "in_internal.h" |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 31 | #include "plugins_exts.h" |
Radek Krejci | 7711410 | 2021-03-10 15:21:57 +0100 | [diff] [blame] | 32 | #include "set.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 33 | #include "tree_data.h" |
| 34 | #include "tree_schema.h" |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 35 | |
Radek Krejci | 52b6d51 | 2020-10-12 12:33:17 +0200 | [diff] [blame] | 36 | volatile LY_LOG_LEVEL ly_ll = LY_LLWRN; |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 37 | volatile uint32_t ly_log_opts = LY_LOLOG | LY_LOSTORE_LAST; |
Michal Vasko | d808561 | 2020-08-21 12:55:23 +0200 | [diff] [blame] | 38 | static ly_log_clb log_clb; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 39 | static volatile ly_bool path_flag = 1; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 40 | #ifndef NDEBUG |
Radek Krejci | 68433c9 | 2020-10-12 17:03:55 +0200 | [diff] [blame] | 41 | volatile uint32_t ly_ldbg_groups = 0; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 42 | #endif |
| 43 | |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 44 | THREAD_LOCAL struct ly_log_location_s log_location = {0}; |
| 45 | |
Radek Krejci | 94aa994 | 2018-09-07 17:12:17 +0200 | [diff] [blame] | 46 | /* how many bytes add when enlarging buffers */ |
| 47 | #define LY_BUF_STEP 128 |
| 48 | |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 49 | API LY_ERR |
| 50 | ly_errcode(const struct ly_ctx *ctx) |
| 51 | { |
| 52 | struct ly_err_item *i; |
| 53 | |
Radek Krejci | 572ee60 | 2020-09-16 14:35:08 +0200 | [diff] [blame] | 54 | i = ly_err_last(ctx); |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 55 | if (i) { |
Radek Krejci | 572ee60 | 2020-09-16 14:35:08 +0200 | [diff] [blame] | 56 | return i->no; |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | return LY_SUCCESS; |
| 60 | } |
| 61 | |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 62 | API LY_VECODE |
| 63 | ly_vecode(const struct ly_ctx *ctx) |
| 64 | { |
| 65 | struct ly_err_item *i; |
| 66 | |
Radek Krejci | 572ee60 | 2020-09-16 14:35:08 +0200 | [diff] [blame] | 67 | i = ly_err_last(ctx); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 68 | if (i) { |
Radek Krejci | 572ee60 | 2020-09-16 14:35:08 +0200 | [diff] [blame] | 69 | return i->vecode; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | return LYVE_SUCCESS; |
| 73 | } |
| 74 | |
| 75 | API const char * |
| 76 | ly_errmsg(const struct ly_ctx *ctx) |
| 77 | { |
| 78 | struct ly_err_item *i; |
| 79 | |
Michal Vasko | b3d0d6b | 2018-09-07 10:17:33 +0200 | [diff] [blame] | 80 | LY_CHECK_ARG_RET(NULL, ctx, NULL); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 81 | |
Radek Krejci | 572ee60 | 2020-09-16 14:35:08 +0200 | [diff] [blame] | 82 | i = ly_err_last(ctx); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 83 | if (i) { |
Radek Krejci | 572ee60 | 2020-09-16 14:35:08 +0200 | [diff] [blame] | 84 | return i->msg; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | return NULL; |
| 88 | } |
| 89 | |
| 90 | API const char * |
| 91 | ly_errpath(const struct ly_ctx *ctx) |
| 92 | { |
| 93 | struct ly_err_item *i; |
| 94 | |
Michal Vasko | b3d0d6b | 2018-09-07 10:17:33 +0200 | [diff] [blame] | 95 | LY_CHECK_ARG_RET(NULL, ctx, NULL); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 96 | |
Radek Krejci | 572ee60 | 2020-09-16 14:35:08 +0200 | [diff] [blame] | 97 | i = ly_err_last(ctx); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 98 | if (i) { |
Radek Krejci | 572ee60 | 2020-09-16 14:35:08 +0200 | [diff] [blame] | 99 | return i->path; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | return NULL; |
| 103 | } |
| 104 | |
| 105 | API const char * |
| 106 | ly_errapptag(const struct ly_ctx *ctx) |
| 107 | { |
| 108 | struct ly_err_item *i; |
| 109 | |
Michal Vasko | b3d0d6b | 2018-09-07 10:17:33 +0200 | [diff] [blame] | 110 | LY_CHECK_ARG_RET(NULL, ctx, NULL); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 111 | |
Radek Krejci | 572ee60 | 2020-09-16 14:35:08 +0200 | [diff] [blame] | 112 | i = ly_err_last(ctx); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 113 | if (i) { |
Radek Krejci | 572ee60 | 2020-09-16 14:35:08 +0200 | [diff] [blame] | 114 | return i->apptag; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | return NULL; |
| 118 | } |
| 119 | |
Radek Krejci | db0ee02 | 2021-03-15 16:53:44 +0100 | [diff] [blame] | 120 | API LY_ERR |
aPiecek | 6d61855 | 2021-06-18 10:02:59 +0200 | [diff] [blame] | 121 | 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] | 122 | { |
Radek Krejci | db0ee02 | 2021-03-15 16:53:44 +0100 | [diff] [blame] | 123 | char *msg = NULL; |
| 124 | struct ly_err_item *e; |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 125 | |
Radek Krejci | d43298b | 2021-03-25 16:17:15 +0100 | [diff] [blame] | 126 | if (!err || (ecode == LY_SUCCESS)) { |
Radek Krejci | db0ee02 | 2021-03-15 16:53:44 +0100 | [diff] [blame] | 127 | /* nothing to do */ |
| 128 | return ecode; |
| 129 | } |
| 130 | |
| 131 | e = malloc(sizeof *e); |
| 132 | LY_CHECK_ERR_RET(!e, LOGMEM(NULL), LY_EMEM); |
| 133 | e->prev = (*err) ? (*err)->prev : e; |
| 134 | e->next = NULL; |
| 135 | if (*err) { |
| 136 | (*err)->prev->next = e; |
| 137 | } |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 138 | |
| 139 | /* fill in the information */ |
Radek Krejci | db0ee02 | 2021-03-15 16:53:44 +0100 | [diff] [blame] | 140 | e->level = LY_LLERR; |
| 141 | e->no = ecode; |
| 142 | e->vecode = vecode; |
| 143 | e->path = path; |
| 144 | e->apptag = apptag; |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 145 | |
aPiecek | 6d61855 | 2021-06-18 10:02:59 +0200 | [diff] [blame] | 146 | if (err_format) { |
Radek Krejci | db0ee02 | 2021-03-15 16:53:44 +0100 | [diff] [blame] | 147 | va_list print_args; |
| 148 | |
aPiecek | 6d61855 | 2021-06-18 10:02:59 +0200 | [diff] [blame] | 149 | va_start(print_args, err_format); |
Radek Krejci | db0ee02 | 2021-03-15 16:53:44 +0100 | [diff] [blame] | 150 | |
aPiecek | 6d61855 | 2021-06-18 10:02:59 +0200 | [diff] [blame] | 151 | if (vasprintf(&msg, err_format, print_args) == -1) { |
| 152 | /* 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] | 153 | * still keep the information about the original error instead of LY_EMEM or other printf's error */ |
| 154 | msg = NULL; |
| 155 | } |
| 156 | |
| 157 | va_end(print_args); |
| 158 | } |
| 159 | e->msg = msg; |
| 160 | |
| 161 | if (!(*err)) { |
| 162 | *err = e; |
| 163 | } |
| 164 | |
| 165 | return e->no; |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | API struct ly_err_item * |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 169 | ly_err_first(const struct ly_ctx *ctx) |
| 170 | { |
Michal Vasko | b3d0d6b | 2018-09-07 10:17:33 +0200 | [diff] [blame] | 171 | LY_CHECK_ARG_RET(NULL, ctx, NULL); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 172 | |
| 173 | return pthread_getspecific(ctx->errlist_key); |
| 174 | } |
| 175 | |
Radek Krejci | 572ee60 | 2020-09-16 14:35:08 +0200 | [diff] [blame] | 176 | API struct ly_err_item * |
| 177 | ly_err_last(const struct ly_ctx *ctx) |
| 178 | { |
| 179 | const struct ly_err_item *e; |
| 180 | |
| 181 | LY_CHECK_ARG_RET(NULL, ctx, NULL); |
| 182 | |
| 183 | e = pthread_getspecific(ctx->errlist_key); |
| 184 | return e ? e->prev : NULL; |
| 185 | } |
| 186 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 187 | API void |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 188 | ly_err_free(void *ptr) |
| 189 | { |
| 190 | struct ly_err_item *i, *next; |
| 191 | |
| 192 | /* clean the error list */ |
| 193 | for (i = (struct ly_err_item *)ptr; i; i = next) { |
| 194 | next = i->next; |
Radek Krejci | db0ee02 | 2021-03-15 16:53:44 +0100 | [diff] [blame] | 195 | free(i->msg); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 196 | free(i->path); |
| 197 | free(i->apptag); |
| 198 | free(i); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | API void |
| 203 | ly_err_clean(struct ly_ctx *ctx, struct ly_err_item *eitem) |
| 204 | { |
| 205 | struct ly_err_item *i, *first; |
| 206 | |
| 207 | first = ly_err_first(ctx); |
| 208 | if (first == eitem) { |
| 209 | eitem = NULL; |
| 210 | } |
| 211 | if (eitem) { |
| 212 | /* disconnect the error */ |
Radek Krejci | 1e008d2 | 2020-08-17 11:37:37 +0200 | [diff] [blame] | 213 | for (i = first; i && (i->next != eitem); i = i->next) {} |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 214 | assert(i); |
| 215 | i->next = NULL; |
| 216 | first->prev = i; |
| 217 | /* free this err and newer */ |
| 218 | ly_err_free(eitem); |
| 219 | } else { |
| 220 | /* free all err */ |
| 221 | ly_err_free(first); |
| 222 | pthread_setspecific(ctx->errlist_key, NULL); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | API LY_LOG_LEVEL |
Radek Krejci | 52b6d51 | 2020-10-12 12:33:17 +0200 | [diff] [blame] | 227 | ly_log_level(LY_LOG_LEVEL level) |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 228 | { |
Radek Krejci | 52b6d51 | 2020-10-12 12:33:17 +0200 | [diff] [blame] | 229 | LY_LOG_LEVEL prev = ly_ll; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 230 | |
Radek Krejci | 52b6d51 | 2020-10-12 12:33:17 +0200 | [diff] [blame] | 231 | ly_ll = level; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 232 | return prev; |
| 233 | } |
| 234 | |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 235 | API uint32_t |
| 236 | ly_log_options(uint32_t opts) |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 237 | { |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 238 | uint32_t prev = ly_log_opts; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 239 | |
| 240 | ly_log_opts = opts; |
| 241 | return prev; |
| 242 | } |
| 243 | |
Radek Krejci | ebdaed0 | 2020-11-09 13:05:06 +0100 | [diff] [blame] | 244 | API uint32_t |
Radek Krejci | 68433c9 | 2020-10-12 17:03:55 +0200 | [diff] [blame] | 245 | ly_log_dbg_groups(uint32_t dbg_groups) |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 246 | { |
| 247 | #ifndef NDEBUG |
Radek Krejci | ebdaed0 | 2020-11-09 13:05:06 +0100 | [diff] [blame] | 248 | uint32_t prev = ly_ldbg_groups; |
| 249 | |
Radek Krejci | 68433c9 | 2020-10-12 17:03:55 +0200 | [diff] [blame] | 250 | ly_ldbg_groups = dbg_groups; |
Radek Krejci | ebdaed0 | 2020-11-09 13:05:06 +0100 | [diff] [blame] | 251 | return prev; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 252 | #else |
| 253 | (void)dbg_groups; |
Radek Krejci | ebdaed0 | 2020-11-09 13:05:06 +0100 | [diff] [blame] | 254 | return 0; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 255 | #endif |
| 256 | } |
| 257 | |
| 258 | API void |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 259 | ly_set_log_clb(ly_log_clb clb, ly_bool path) |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 260 | { |
Michal Vasko | d808561 | 2020-08-21 12:55:23 +0200 | [diff] [blame] | 261 | log_clb = clb; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 262 | path_flag = path; |
| 263 | } |
| 264 | |
Michal Vasko | d808561 | 2020-08-21 12:55:23 +0200 | [diff] [blame] | 265 | API ly_log_clb |
| 266 | ly_get_log_clb(void) |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 267 | { |
Michal Vasko | d808561 | 2020-08-21 12:55:23 +0200 | [diff] [blame] | 268 | return log_clb; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 269 | } |
| 270 | |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 271 | void |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 272 | ly_log_location(const struct lysc_node *scnode, const struct lyd_node *dnode, |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 273 | const char *path, const struct ly_in *in, uint64_t line, ly_bool reset) |
| 274 | { |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 275 | if (scnode) { |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 276 | ly_set_add(&log_location.scnodes, (void *)scnode, 1, NULL); |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 277 | } else if (reset) { |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 278 | ly_set_erase(&log_location.scnodes, NULL); |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | if (dnode) { |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 282 | ly_set_add(&log_location.dnodes, (void *)dnode, 1, NULL); |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 283 | } else if (reset) { |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 284 | ly_set_erase(&log_location.dnodes, NULL); |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | if (path) { |
| 288 | char *s = strdup(path); |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 289 | LY_CHECK_ERR_RET(!s, LOGMEM(NULL), ); |
| 290 | ly_set_add(&log_location.paths, s, 1, NULL); |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 291 | } else if (reset) { |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 292 | ly_set_erase(&log_location.paths, free); |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | if (in) { |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 296 | ly_set_add(&log_location.inputs, (void *)in, 1, NULL); |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 297 | } else if (reset) { |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 298 | ly_set_erase(&log_location.inputs, NULL); |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | if (line) { |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 302 | log_location.line = line; |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | |
| 306 | void |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 307 | ly_log_location_revert(uint32_t scnode_steps, uint32_t dnode_steps, |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 308 | uint32_t path_steps, uint32_t in_steps) |
| 309 | { |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 310 | for (uint32_t i = scnode_steps; i && log_location.scnodes.count; i--) { |
| 311 | log_location.scnodes.count--; |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 312 | } |
| 313 | |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 314 | for (uint32_t i = dnode_steps; i && log_location.dnodes.count; i--) { |
| 315 | log_location.dnodes.count--; |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 316 | } |
| 317 | |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 318 | for (uint32_t i = path_steps; i && log_location.paths.count; i--) { |
| 319 | 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] | 320 | } |
| 321 | |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 322 | for (uint32_t i = in_steps; i && log_location.inputs.count; i--) { |
| 323 | log_location.inputs.count--; |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 324 | } |
| 325 | |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 326 | /* deallocate the empty sets */ |
| 327 | if (scnode_steps && !log_location.scnodes.count) { |
| 328 | ly_set_erase(&log_location.scnodes, NULL); |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 329 | } |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 330 | if (dnode_steps && !log_location.dnodes.count) { |
| 331 | ly_set_erase(&log_location.dnodes, NULL); |
| 332 | } |
| 333 | if (path_steps && !log_location.paths.count) { |
| 334 | ly_set_erase(&log_location.paths, free); |
| 335 | } |
| 336 | if (in_steps && !log_location.inputs.count) { |
| 337 | ly_set_erase(&log_location.inputs, NULL); |
Radek Krejci | addfc9a | 2020-12-17 20:46:35 +0100 | [diff] [blame] | 338 | } |
| 339 | } |
| 340 | |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 341 | static LY_ERR |
| 342 | log_store(const struct ly_ctx *ctx, LY_LOG_LEVEL level, LY_ERR no, LY_VECODE vecode, char *msg, char *path, char *apptag) |
| 343 | { |
| 344 | struct ly_err_item *eitem, *last; |
| 345 | |
| 346 | assert(ctx && (level < LY_LLVRB)); |
| 347 | |
| 348 | eitem = pthread_getspecific(ctx->errlist_key); |
| 349 | if (!eitem) { |
| 350 | /* if we are only to fill in path, there must have been an error stored */ |
| 351 | assert(msg); |
| 352 | eitem = malloc(sizeof *eitem); |
| 353 | LY_CHECK_GOTO(!eitem, mem_fail); |
| 354 | eitem->prev = eitem; |
| 355 | eitem->next = NULL; |
| 356 | |
| 357 | pthread_setspecific(ctx->errlist_key, eitem); |
| 358 | } else if (!msg) { |
| 359 | /* only filling the path */ |
| 360 | assert(path); |
| 361 | |
| 362 | /* find last error */ |
| 363 | eitem = eitem->prev; |
| 364 | do { |
| 365 | if (eitem->level == LY_LLERR) { |
| 366 | /* fill the path */ |
| 367 | free(eitem->path); |
| 368 | eitem->path = path; |
| 369 | return LY_SUCCESS; |
| 370 | } |
| 371 | eitem = eitem->prev; |
| 372 | } while (eitem->prev->next); |
| 373 | /* last error was not found */ |
| 374 | assert(0); |
Michal Vasko | ed94a29 | 2019-11-06 15:43:41 +0100 | [diff] [blame] | 375 | } else if ((ly_log_opts & LY_LOSTORE_LAST) == LY_LOSTORE_LAST) { |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 376 | /* overwrite last message */ |
| 377 | free(eitem->msg); |
| 378 | free(eitem->path); |
| 379 | free(eitem->apptag); |
| 380 | } else { |
| 381 | /* store new message */ |
| 382 | last = eitem->prev; |
| 383 | eitem->prev = malloc(sizeof *eitem); |
| 384 | LY_CHECK_GOTO(!eitem->prev, mem_fail); |
| 385 | eitem = eitem->prev; |
| 386 | eitem->prev = last; |
| 387 | eitem->next = NULL; |
| 388 | last->next = eitem; |
| 389 | } |
| 390 | |
| 391 | /* fill in the information */ |
| 392 | eitem->level = level; |
| 393 | eitem->no = no; |
| 394 | eitem->vecode = vecode; |
| 395 | eitem->msg = msg; |
| 396 | eitem->path = path; |
| 397 | eitem->apptag = apptag; |
| 398 | return LY_SUCCESS; |
| 399 | |
| 400 | mem_fail: |
| 401 | LOGMEM(NULL); |
| 402 | free(msg); |
| 403 | free(path); |
| 404 | free(apptag); |
| 405 | return LY_EMEM; |
| 406 | } |
| 407 | |
| 408 | static void |
| 409 | log_vprintf(const struct ly_ctx *ctx, LY_LOG_LEVEL level, LY_ERR no, LY_VECODE vecode, char *path, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 410 | const char *format, va_list args) |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 411 | { |
| 412 | char *msg = NULL; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 413 | ly_bool free_strs; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 414 | |
Radek Krejci | 52b6d51 | 2020-10-12 12:33:17 +0200 | [diff] [blame] | 415 | if (level > ly_ll) { |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 416 | /* do not print or store the message */ |
| 417 | free(path); |
| 418 | return; |
| 419 | } |
| 420 | |
Michal Vasko | 5a01692 | 2021-05-07 08:19:15 +0200 | [diff] [blame] | 421 | if (no == LY_EMEM) { |
| 422 | /* just print it, anything else would most likely fail anyway */ |
| 423 | if (ly_log_opts & LY_LOLOG) { |
| 424 | if (log_clb) { |
| 425 | log_clb(level, LY_EMEM_MSG, path); |
| 426 | } else { |
| 427 | fprintf(stderr, "libyang[%d]: ", level); |
| 428 | vfprintf(stderr, format, args); |
| 429 | if (path) { |
| 430 | fprintf(stderr, " (path: %s)\n", path); |
| 431 | } else { |
| 432 | fprintf(stderr, "\n"); |
| 433 | } |
| 434 | } |
| 435 | } |
| 436 | free(path); |
| 437 | return; |
| 438 | } |
| 439 | |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 440 | /* store the error/warning (if we need to store errors internally, it does not matter what are the user log options) */ |
Michal Vasko | ed94a29 | 2019-11-06 15:43:41 +0100 | [diff] [blame] | 441 | if ((level < LY_LLVRB) && ctx && (ly_log_opts & LY_LOSTORE)) { |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 442 | assert(format); |
| 443 | if (vasprintf(&msg, format, args) == -1) { |
| 444 | LOGMEM(ctx); |
| 445 | free(path); |
| 446 | return; |
| 447 | } |
Radek Krejci | c9e64a6 | 2020-09-18 20:08:12 +0200 | [diff] [blame] | 448 | if (((no & ~LY_EPLUGIN) == LY_EVALID) && (vecode == LYVE_SUCCESS)) { |
| 449 | /* assume we are inheriting the error, so inherit vecode as well */ |
| 450 | vecode = ly_vecode(ctx); |
| 451 | } |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 452 | if (log_store(ctx, level, no, vecode, msg, path, NULL)) { |
| 453 | return; |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 454 | } |
| 455 | free_strs = 0; |
| 456 | } else { |
| 457 | if (vasprintf(&msg, format, args) == -1) { |
| 458 | LOGMEM(ctx); |
| 459 | free(path); |
| 460 | return; |
| 461 | } |
| 462 | free_strs = 1; |
| 463 | } |
| 464 | |
| 465 | /* if we are only storing errors internally, never print the message (yet) */ |
Michal Vasko | ed94a29 | 2019-11-06 15:43:41 +0100 | [diff] [blame] | 466 | if (ly_log_opts & LY_LOLOG) { |
Michal Vasko | d808561 | 2020-08-21 12:55:23 +0200 | [diff] [blame] | 467 | if (log_clb) { |
| 468 | log_clb(level, msg, path); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 469 | } else { |
| 470 | fprintf(stderr, "libyang[%d]: %s%s", level, msg, path ? " " : "\n"); |
| 471 | if (path) { |
| 472 | fprintf(stderr, "(path: %s)\n", path); |
| 473 | } |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | if (free_strs) { |
| 478 | free(path); |
| 479 | free(msg); |
| 480 | } |
| 481 | } |
| 482 | |
Radek Krejci | 4ab6156 | 2018-09-05 15:00:37 +0200 | [diff] [blame] | 483 | #ifndef NDEBUG |
| 484 | |
| 485 | void |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 486 | ly_log_dbg(uint32_t group, const char *format, ...) |
Radek Krejci | 4ab6156 | 2018-09-05 15:00:37 +0200 | [diff] [blame] | 487 | { |
| 488 | char *dbg_format; |
| 489 | const char *str_group; |
| 490 | va_list ap; |
| 491 | |
Radek Krejci | 68433c9 | 2020-10-12 17:03:55 +0200 | [diff] [blame] | 492 | if (!(ly_ldbg_groups & group)) { |
Radek Krejci | 4ab6156 | 2018-09-05 15:00:37 +0200 | [diff] [blame] | 493 | return; |
| 494 | } |
| 495 | |
| 496 | switch (group) { |
| 497 | case LY_LDGDICT: |
| 498 | str_group = "DICT"; |
| 499 | break; |
Radek Krejci | 4ab6156 | 2018-09-05 15:00:37 +0200 | [diff] [blame] | 500 | case LY_LDGXPATH: |
| 501 | str_group = "XPATH"; |
| 502 | break; |
Radek Krejci | 4ab6156 | 2018-09-05 15:00:37 +0200 | [diff] [blame] | 503 | default: |
| 504 | LOGINT(NULL); |
| 505 | return; |
| 506 | } |
| 507 | |
| 508 | if (asprintf(&dbg_format, "%s: %s", str_group, format) == -1) { |
| 509 | LOGMEM(NULL); |
| 510 | return; |
| 511 | } |
| 512 | |
| 513 | va_start(ap, format); |
| 514 | log_vprintf(NULL, LY_LLDBG, 0, 0, NULL, dbg_format, ap); |
| 515 | va_end(ap); |
| 516 | } |
| 517 | |
| 518 | #endif |
| 519 | |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 520 | void |
| 521 | ly_log(const struct ly_ctx *ctx, LY_LOG_LEVEL level, LY_ERR no, const char *format, ...) |
| 522 | { |
| 523 | va_list ap; |
| 524 | |
| 525 | va_start(ap, format); |
| 526 | log_vprintf(ctx, level, no, 0, NULL, format, ap); |
| 527 | va_end(ap); |
| 528 | } |
| 529 | |
Radek Krejci | 94aa994 | 2018-09-07 17:12:17 +0200 | [diff] [blame] | 530 | static LY_ERR |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 531 | ly_vlog_build_path(const struct ly_ctx *ctx, char **path) |
Radek Krejci | 94aa994 | 2018-09-07 17:12:17 +0200 | [diff] [blame] | 532 | { |
Radek Krejci | c04f0a2 | 2018-09-21 15:49:45 +0200 | [diff] [blame] | 533 | int rc; |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 534 | char *str = NULL, *prev = NULL; |
Radek Krejci | cb3e647 | 2021-01-06 08:19:01 +0100 | [diff] [blame] | 535 | |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 536 | *path = NULL; |
Radek Krejci | 94aa994 | 2018-09-07 17:12:17 +0200 | [diff] [blame] | 537 | |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 538 | 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] | 539 | /* simply get what is in the provided path string */ |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 540 | *path = strdup((const char *)log_location.paths.objs[log_location.paths.count - 1]); |
Radek Krejci | c04f0a2 | 2018-09-21 15:49:45 +0200 | [diff] [blame] | 541 | LY_CHECK_ERR_RET(!(*path), LOGMEM(ctx), LY_EMEM); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 542 | } else { |
| 543 | /* generate location string */ |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 544 | if (log_location.scnodes.count) { |
| 545 | 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] | 546 | LY_CHECK_ERR_RET(!str, LOGMEM(ctx), LY_EMEM); |
| 547 | |
| 548 | rc = asprintf(path, "Schema location %s", str); |
| 549 | free(str); |
| 550 | LY_CHECK_ERR_RET(rc == -1, LOGMEM(ctx), LY_EMEM); |
| 551 | } |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 552 | if (log_location.dnodes.count) { |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 553 | prev = *path; |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 554 | str = lyd_path(log_location.dnodes.objs[log_location.dnodes.count - 1], LYD_PATH_STD, NULL, 0); |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 555 | LY_CHECK_ERR_RET(!str, LOGMEM(ctx), LY_EMEM); |
| 556 | |
| 557 | rc = asprintf(path, "%s%sata location %s", prev ? prev : "", prev ? ", d" : "D", str); |
| 558 | free(str); |
| 559 | free(prev); |
| 560 | LY_CHECK_ERR_RET(rc == -1, LOGMEM(ctx), LY_EMEM); |
| 561 | } |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 562 | if (log_location.line) { |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 563 | prev = *path; |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 564 | rc = 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] | 565 | free(prev); |
| 566 | LY_CHECK_ERR_RET(rc == -1, LOGMEM(ctx), LY_EMEM); |
| 567 | |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 568 | log_location.line = 0; |
| 569 | } else if (log_location.inputs.count) { |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 570 | prev = *path; |
| 571 | rc = asprintf(path, "%s%sine number %" PRIu64, prev ? prev : "", prev ? ", l" : "L", |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 572 | ((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] | 573 | free(prev); |
| 574 | LY_CHECK_ERR_RET(rc == -1, LOGMEM(ctx), LY_EMEM); |
| 575 | } |
| 576 | |
| 577 | if (*path) { |
| 578 | prev = *path; |
| 579 | rc = asprintf(path, "%s.", prev); |
| 580 | free(prev); |
| 581 | LY_CHECK_ERR_RET(rc == -1, LOGMEM(ctx), LY_EMEM); |
| 582 | } |
Radek Krejci | 94aa994 | 2018-09-07 17:12:17 +0200 | [diff] [blame] | 583 | } |
| 584 | |
Radek Krejci | 94aa994 | 2018-09-07 17:12:17 +0200 | [diff] [blame] | 585 | return LY_SUCCESS; |
| 586 | } |
| 587 | |
| 588 | void |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 589 | ly_vlog(const struct ly_ctx *ctx, LY_VECODE code, const char *format, ...) |
Radek Krejci | 94aa994 | 2018-09-07 17:12:17 +0200 | [diff] [blame] | 590 | { |
| 591 | va_list ap; |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 592 | char *path = NULL; |
Radek Krejci | 94aa994 | 2018-09-07 17:12:17 +0200 | [diff] [blame] | 593 | |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 594 | if (path_flag && ctx) { |
Radek Krejci | ddace2c | 2021-01-08 11:30:56 +0100 | [diff] [blame] | 595 | ly_vlog_build_path(ctx, &path); |
Radek Krejci | 94aa994 | 2018-09-07 17:12:17 +0200 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | va_start(ap, format); |
| 599 | log_vprintf(ctx, LY_LLERR, LY_EVALID, code, path, format, ap); |
| 600 | /* path is spent and should not be freed! */ |
| 601 | va_end(ap); |
| 602 | } |
| 603 | |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 604 | API void |
Radek Krejci | 0b01330 | 2021-03-29 15:22:32 +0200 | [diff] [blame] | 605 | lyplg_ext_log(const struct lysc_ext_instance *ext, LY_LOG_LEVEL level, LY_ERR err_no, const char *path, const char *format, ...) |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 606 | { |
| 607 | va_list ap; |
| 608 | char *plugin_msg; |
| 609 | int ret; |
| 610 | |
Radek Krejci | 52b6d51 | 2020-10-12 12:33:17 +0200 | [diff] [blame] | 611 | if (ly_ll < level) { |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 612 | return; |
| 613 | } |
Radek Krejci | 932d3bb | 2021-02-09 16:29:38 +0100 | [diff] [blame] | 614 | ret = asprintf(&plugin_msg, "Extension plugin \"%s\": %s", ext->def->plugin->id, format); |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 615 | if (ret == -1) { |
Radek Krejci | 28681fa | 2019-09-06 13:08:45 +0200 | [diff] [blame] | 616 | LOGMEM(ext->module->ctx); |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 617 | return; |
| 618 | } |
| 619 | |
| 620 | va_start(ap, format); |
Radek Krejci | a4614e6 | 2020-05-15 14:19:28 +0200 | [diff] [blame] | 621 | log_vprintf(ext->module->ctx, level, (level == LY_LLERR ? LY_EPLUGIN : 0) | err_no, LYVE_OTHER, path ? strdup(path) : NULL, plugin_msg, ap); |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 622 | va_end(ap); |
| 623 | |
| 624 | free(plugin_msg); |
| 625 | } |
| 626 | |
Michal Vasko | 177d0ed | 2020-11-23 16:43:03 +0100 | [diff] [blame] | 627 | /** |
Michal Vasko | c78a609 | 2021-05-07 15:27:35 +0200 | [diff] [blame] | 628 | * @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] | 629 | */ |
| 630 | static void |
Michal Vasko | c78a609 | 2021-05-07 15:27:35 +0200 | [diff] [blame] | 631 | _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] | 632 | { |
Michal Vasko | 177d0ed | 2020-11-23 16:43:03 +0100 | [diff] [blame] | 633 | va_list ap; |
| 634 | char *path_dup = NULL; |
| 635 | |
| 636 | LY_CHECK_ARG_RET(ctx, eitem, ); |
| 637 | |
| 638 | if (eitem->path) { |
| 639 | /* duplicate path because it will be freed */ |
| 640 | path_dup = strdup(eitem->path); |
| 641 | LY_CHECK_ERR_RET(!path_dup, LOGMEM(ctx), ); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 642 | } |
Michal Vasko | 177d0ed | 2020-11-23 16:43:03 +0100 | [diff] [blame] | 643 | |
Michal Vasko | c78a609 | 2021-05-07 15:27:35 +0200 | [diff] [blame] | 644 | va_start(ap, format); |
| 645 | log_vprintf(ctx, eitem->level, eitem->no, eitem->vecode, path_dup, format, ap); |
Michal Vasko | 177d0ed | 2020-11-23 16:43:03 +0100 | [diff] [blame] | 646 | va_end(ap); |
Michal Vasko | 177d0ed | 2020-11-23 16:43:03 +0100 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | API void |
| 650 | ly_err_print(const struct ly_ctx *ctx, struct ly_err_item *eitem) |
| 651 | { |
Michal Vasko | c78a609 | 2021-05-07 15:27:35 +0200 | [diff] [blame] | 652 | /* String ::ly_err_item.msg cannot be used directly because it may contain the % character */ |
| 653 | _ly_err_print(ctx, eitem, "%s", eitem->msg); |
Radek Krejci | 5aeea3a | 2018-09-05 13:29:36 +0200 | [diff] [blame] | 654 | } |