blob: c98edac397bf5adfb76d0df46b7949dce5414fa8 [file] [log] [blame]
Radek Krejci5aeea3a2018-09-05 13:29:36 +02001/**
2 * @file log.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
Michal Vasko193dacd2022-10-13 08:43:05 +02004 * @author Michal Vasko <mvasko@cesnet.cz>
Radek Krejci5aeea3a2018-09-05 13:29:36 +02005 * @brief Logger manipulation routines and error definitions.
6 *
Michal Vasko193dacd2022-10-13 08:43:05 +02007 * Copyright (c) 2015 - 2022 CESNET, z.s.p.o.
Radek Krejci5aeea3a2018-09-05 13:29:36 +02008 *
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
16#ifndef LY_LOG_H_
17#define LY_LOG_H_
18
Radek Krejci1deb5be2020-08-26 16:43:36 +020019#include <stdint.h>
20
Michal Vasko8f702ee2024-02-20 15:44:24 +010021#include "ly_config.h"
Jan Kundrátc53a7ec2021-12-09 16:01:19 +010022
Radek Krejci5aeea3a2018-09-05 13:29:36 +020023#ifdef __cplusplus
24extern "C" {
25#endif
26
Radek Krejciad573502018-09-07 15:26:55 +020027/* dummy context structure */
28struct ly_ctx;
29
Radek Krejci5aeea3a2018-09-05 13:29:36 +020030/**
Radek Krejci857189e2020-09-01 13:26:36 +020031 * @brief Type to indicate boolean value.
32 *
33 * Do not test for actual value. Instead, handle it as true/false value in condition.
34 */
35typedef uint8_t ly_bool;
36
37/**
Radek Krejci8678fa42020-08-18 16:07:28 +020038 * @page howtoLogger Information Logging
39 *
40 * The libyang logger is supposed to process all the messages (and some other accompanied information) generated by the performed
41 * functions. According to the logger settings, the information can be printed, stored or further processed by a callback
42 * functions.
43 *
44 * The logger is tightly connected with [errors handling](@ref howtoErrors), because when an error appears, the logger (according
45 * to [logger options](@ref logopts)) generates error records available via libyang context.
46 *
47 * There are 4 verbosity levels defined as ::LY_LOG_LEVEL. The level can be changed by the ::ly_log_level() function.
48 * By default, the verbosity level is set to #LY_LLERR value, so only the errors are processed.
49 *
50 * By default, all libyang messages are printed to `stderr`. However, the callers are able to set their own logging callback
51 * function (::ly_log_clb). In that case, instead of printing messages, libyang passes error level, message and path (if any) to
52 * the caller's callback function set via ::ly_set_log_clb(). In case of error level, the error information is still
53 * automatically stored and available via the [error handling functions](@ref howtoErrors).
54 *
55 * With [logging options](@ref logopts) set via ::ly_log_options(), the caller can modify what is done with all the messages.
56 * Default flags are ::LY_LOLOG and ::LY_LOSTORE_LAST so that messages are logged and the last one is stored. If you set the flag
57 * ::LY_LOSTORE, all the messages will be stored. Be careful because unless you regularly clean them, the error list in context
58 * will grow indefinitely.
59 *
60 * As a separate group, there are @ref dbggroup to select group of debugging messages to print. The options can be set via
61 * ::ly_log_dbg_groups() function, but note that the options take effect only in case the libyang is compiled in
Radek Krejci7132fc52020-10-26 14:34:06 +010062 * [Debug build mode](@ref build).
Radek Krejci8678fa42020-08-18 16:07:28 +020063 *
64 * \note API for this group of functions is described in the [logger module](@ref log).
65 *
66 * Functions List
67 * --------------
68 * - ::ly_log_level()
69 * - ::ly_log_dbg_groups()
70 * - ::ly_log_options()
71 * - ::ly_set_log_clb()
72 * - ::ly_get_log_clb()
73 *
74 */
75
76/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +020077 * @defgroup log Logger
78 * @{
79 *
80 * Publicly visible functions and values of the libyang logger. For more
Michal Vasko8906ac12021-11-25 11:14:59 +010081 * information, see @ref howtoLogger.
Radek Krejci5aeea3a2018-09-05 13:29:36 +020082 */
83
84/**
85 * @typedef LY_LOG_LEVEL
86 * @brief Verbosity levels of the libyang logger.
87 */
Michal Vasko26bbb272022-08-02 14:54:33 +020088typedef enum {
Michal Vasko8906ac12021-11-25 11:14:59 +010089 LY_LLERR = 0, /**< Print only error messages. */
90 LY_LLWRN = 1, /**< Print error and warning messages, default value. */
Radek Krejci5aeea3a2018-09-05 13:29:36 +020091 LY_LLVRB = 2, /**< Besides errors and warnings, print some other verbose messages. */
Michal Vasko8906ac12021-11-25 11:14:59 +010092 LY_LLDBG = 3 /**< Print all messages including some development debug messages (be careful,
93 without subsequently calling ::ly_log_dbg_groups() no debug messages will be printed!). */
Radek Krejci5aeea3a2018-09-05 13:29:36 +020094} LY_LOG_LEVEL;
95
96/**
97 * @brief Set logger verbosity level.
Radek Krejciebdaed02020-11-09 13:05:06 +010098 *
aPiecekb0445f22021-06-24 11:34:07 +020099 * To get the current value, the function must be called twice resetting the level by the received value.
Radek Krejciebdaed02020-11-09 13:05:06 +0100100 *
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200101 * @param[in] level Verbosity level.
102 * @return Previous verbosity level.
103 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +0100104LIBYANG_API_DECL LY_LOG_LEVEL ly_log_level(LY_LOG_LEVEL level);
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200105
106/**
Michal Vasko2c1f66d2024-01-22 14:36:13 +0100107 * @ingroup log
Radek Krejci8678fa42020-08-18 16:07:28 +0200108 * @defgroup logopts Logging options
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200109 *
110 * Logging option bits of libyang.
111 *
Radek Krejci8678fa42020-08-18 16:07:28 +0200112 * Can be set via ::ly_log_options().
113 *
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200114 * @{
115 */
116#define LY_LOLOG 0x01 /**< Log messages normally, using callback if set. If not set, messages will
117 not be printed by libyang. */
118#define LY_LOSTORE 0x02 /**< Store any generated errors or warnings, never verbose or debug messages.
119 Note that if #LY_LOLOG is not set then verbose and debug messages are always lost. */
120#define LY_LOSTORE_LAST 0x06 /**< Store any generated errors or warnings but only the last message, always overwrite
121 the previous one. */
122
123/**
124 * @}
125 */
126
127/**
Radek Krejci8678fa42020-08-18 16:07:28 +0200128 * @brief Set logger options. Default is #LY_LOLOG | #LY_LOSTORE_LAST.
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200129 *
aPiecekb0445f22021-06-24 11:34:07 +0200130 * To get the current value, the function must be called twice resetting the level by the received value.
Radek Krejciebdaed02020-11-09 13:05:06 +0100131 *
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200132 * @param[in] opts Bitfield of @ref logopts.
133 * @return Previous logger options.
134 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +0100135LIBYANG_API_DECL uint32_t ly_log_options(uint32_t opts);
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200136
Michal Vaskod4a6d042022-12-08 08:34:29 +0100137/**
138 * @brief Set temporary thread-safe logger options overwriting those set by ::ly_log_options().
139 *
140 * @param[in] opts Pointer to the temporary @ref logopts. If NULL, restores the effect of global logger options.
Michal Vasko52da51d2024-01-30 16:09:19 +0100141 * @return Previous temporary options.
Michal Vaskod4a6d042022-12-08 08:34:29 +0100142 */
Michal Vasko52da51d2024-01-30 16:09:19 +0100143LIBYANG_API_DECL uint32_t *ly_temp_log_options(uint32_t *opts);
Michal Vaskod4a6d042022-12-08 08:34:29 +0100144
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200145/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200146 * @ingroup log
Radek Krejci8678fa42020-08-18 16:07:28 +0200147 * @defgroup dbggroup Debug messages groups
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200148 *
Radek Krejci8678fa42020-08-18 16:07:28 +0200149 * Categories of the debug messages.
150 *
151 * Allows to show only the selected group(s) of the debug messages.
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200152 *
153 * @{
154 */
155
Michal Vaskoe558f792021-07-28 08:20:15 +0200156#define LY_LDGDICT 0x01 /**< Dictionary additions and deletions. */
157#define LY_LDGXPATH 0x02 /**< XPath parsing end evaluation. */
158#define LY_LDGDEPSETS 0x04 /**< Dependency module sets for schema compilation. */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200159
160/**
161 * @}
162 */
163
164/**
165 * @brief Enable specific debugging messages (independent of log level).
Radek Krejciebdaed02020-11-09 13:05:06 +0100166 *
aPiecekb0445f22021-06-24 11:34:07 +0200167 * To get the current value, the function must be called twice resetting the level by the received value.
Thomas Egererdc0c7202023-10-23 15:47:15 +0200168 * Note: does not have any effect on non-debug (Release) builds
Radek Krejciebdaed02020-11-09 13:05:06 +0100169 *
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200170 * @param[in] dbg_groups Bitfield of enabled debug message groups (see @ref dbggroup).
Radek Krejciebdaed02020-11-09 13:05:06 +0100171 * @return Previous options bitfield.
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200172 */
aPiecek3af0d452023-05-30 11:40:35 +0200173LIBYANG_API_DECL uint32_t ly_log_dbg_groups(uint32_t dbg_groups);
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200174
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200175/**
Michal Vaskod8085612020-08-21 12:55:23 +0200176 * @brief Logger callback.
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200177 *
178 * !IMPORTANT! If an error has a specific error-app-tag defined in the model, it will NOT be set
179 * at the time of calling this callback. It will be set right after, so to retrieve it
Radek Krejci8678fa42020-08-18 16:07:28 +0200180 * it must be checked afterwards with ::ly_errapptag().
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200181 *
Michal Vaskod8085612020-08-21 12:55:23 +0200182 * @param[in] level Log level of the message.
183 * @param[in] msg Message.
184 * @param[in] path Optional path of the concerned node.
185 */
186typedef void (*ly_log_clb)(LY_LOG_LEVEL level, const char *msg, const char *path);
187
188/**
189 * @brief Set logger callback.
190 *
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200191 * @param[in] clb Logging callback.
192 * @param[in] path flag to resolve and provide path as the third parameter of the callback function. In case of
193 * validation and some other errors, it can be useful to get the path to the problematic element. Note,
194 * that according to the tree type and the specific situation, the path can slightly differs (keys
195 * presence) or it can be NULL, so consider it as an optional parameter. If the flag is 0, libyang will
196 * not bother with resolving the path.
197 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +0100198LIBYANG_API_DECL void ly_set_log_clb(ly_log_clb clb, ly_bool path);
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200199
200/**
201 * @brief Get logger callback.
202 * @return Logger callback (can be NULL).
203 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +0100204LIBYANG_API_DECL ly_log_clb ly_get_log_clb(void);
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200205
206/** @} log */
207
208/**
Radek Krejci8678fa42020-08-18 16:07:28 +0200209 * @page howtoErrors Errors Handling
210 *
211 * The most of the API functions directly returns error code in the form of ::LY_ERR value. In addition, if the ::LY_EVALID error
212 * arises, additional [validation error code](@ref ::LY_VECODE) is provided to categorize validation failures into several groups.
213 *
214 * All the errors arisen in connection with manipulation with the [context](@ref howtoContext), [YANG modules](@ref howtoSchema)
215 * or [YANG data](@ref howtoData), are recorded into the context and can be examined for the more detailed information. These
216 * records are stored as ::ly_err_item structures and they are not only context-specific, but also thread-specific.
217 *
218 * Storing error information is tightly connected with
219 * [logging](@ref howtoLogger). So the @ref logopts control if and which errors are stored in the context. By default, only the
220 * last error is recorded, so a new error replaces the previous one. This can be changed with ::LY_LOSTORE option set via
221 * ::ly_log_options(). Then, the errors are stored as a list preserving the previous error records. The stored records can be
222 * accessed using ::ly_err_last() or ::ly_err_first() functions. The ::ly_err_clean() is used to remove error records from the
223 * context.
224 *
225 * To print a specific error information via libyang logger, there is ::ly_err_print().
226 *
227 * To simplify access to the last error record in the context, there is a set of functions returning important error information.
228 * - ::ly_errapptag()
229 * - ::ly_errcode()
230 * - ::ly_vecode()
231 * - ::ly_errmsg()
232 * - ::ly_errpath()
233 *
234 * \note API for this group of functions is described in the [error information module](@ref errors).
235 */
236
237/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200238 * @defgroup errors Error information
Radek Krejci8678fa42020-08-18 16:07:28 +0200239 *
240 * Structures and functions to allow error information processing.
241 *
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200242 * @{
243 */
244
245/**
246 * @typedef LY_ERR
247 * @brief libyang's error codes returned by the libyang functions.
248 */
Michal Vaskoddd76592022-01-17 13:34:48 +0100249typedef enum {
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200250 LY_SUCCESS = 0, /**< no error, not set by functions, included just to complete #LY_ERR enumeration */
251 LY_EMEM, /**< Memory allocation failure */
Radek Krejcidc1c7e72018-09-07 14:58:20 +0200252 LY_ESYS, /**< System call failure */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200253 LY_EINVAL, /**< Invalid value */
254 LY_EEXIST, /**< Item already exists */
Radek Krejcid33273d2018-10-25 14:55:52 +0200255 LY_ENOTFOUND, /**< Item does not exists */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200256 LY_EINT, /**< Internal error */
257 LY_EVALID, /**< Validation failure */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200258 LY_EDENIED, /**< Operation is not allowed */
Michal Vasko1ccbf542021-04-19 11:35:00 +0200259 LY_EINCOMPLETE, /**< The operation did not fail, but for some reason it was not possible to finish it completely.
Radek Krejcie553e6d2019-06-07 15:33:18 +0200260 According to the specific use case, the caller is usually supposed to perform the operation again. */
Michal Vasko1ccbf542021-04-19 11:35:00 +0200261 LY_ERECOMPILE, /**< The operation did not fail, but requires context recompilation before it can be completed.
262 According to the specific use case, the caller should react appropriately. */
Radek Krejci1f05b6a2019-07-18 16:15:06 +0200263 LY_ENOT, /**< Negative result */
Radek Krejcia4614e62020-05-15 14:19:28 +0200264 LY_EOTHER, /**< Unknown error */
265
266 LY_EPLUGIN = 128/**< Error reported by a plugin - the highest bit in the first byte is set.
267 This value is used ORed with one of the other LY_ERR value and can be simply masked. */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200268} LY_ERR;
269
270/**
Michal Vasko2c1f66d2024-01-22 14:36:13 +0100271 * @ingroup log
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200272 * @typedef LY_VECODE
273 * @brief libyang's codes of validation error. Whenever ly_errno is set to LY_EVALID, the ly_vecode is also set
274 * to the appropriate LY_VECODE value.
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200275 */
276typedef enum {
277 LYVE_SUCCESS = 0, /**< no error */
Radek Krejci94aa9942018-09-07 17:12:17 +0200278 LYVE_SYNTAX, /**< generic syntax error */
279 LYVE_SYNTAX_YANG, /**< YANG-related syntax error */
David Sedlák0a875b42019-03-07 22:24:05 +0100280 LYVE_SYNTAX_YIN, /**< YIN-related syntax error */
Radek Krejci70853c52018-10-15 14:46:16 +0200281 LYVE_REFERENCE, /**< invalid referencing or using an item */
Radek Krejcib1646a92018-11-02 16:08:26 +0100282 LYVE_XPATH, /**< invalid XPath expression */
Radek Krejcie7b95092019-05-15 11:03:07 +0200283 LYVE_SEMANTICS, /**< generic semantic error */
284 LYVE_SYNTAX_XML, /**< XML-related syntax error */
Radek Krejci1798aae2020-07-14 13:26:06 +0200285 LYVE_SYNTAX_JSON, /**< JSON-related syntax error */
Michal Vaskoecd62de2019-11-13 12:35:11 +0100286 LYVE_DATA, /**< YANG data does not reflect some of the module restrictions */
Radek Krejcia4614e62020-05-15 14:19:28 +0200287
288 LYVE_OTHER /**< Unknown error */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200289} LY_VECODE;
290
291/**
292 * @brief Libyang full error structure.
293 */
294struct ly_err_item {
Michal Vaskodab9cc92023-07-10 10:35:42 +0200295 LY_LOG_LEVEL level; /**< error (message) log level */
296 LY_ERR no; /**< error code */
297 LY_VECODE vecode; /**< validation error code, if any */
298 char *msg; /**< error message */
299 char *path; /**< error path that caused the error, if any */
300 char *apptag; /**< error-app-tag, if any */
301 struct ly_err_item *next; /**< next error item */
302 struct ly_err_item *prev; /**< previous error item, points to the last item for the ifrst item */
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200303};
304
305/**
Michal Vaskob5b883c2023-07-10 10:36:18 +0200306 * @brief Get the last (thread, context-specific) error code.
Michal Vasko236cbac2023-02-10 15:45:37 +0100307 *
Michal Vaskob5b883c2023-07-10 10:36:18 +0200308 * @param[in] ctx Relative context.
309 * @return LY_ERR value of the last error code.
Michal Vasko236cbac2023-02-10 15:45:37 +0100310 */
Michal Vaskob5b883c2023-07-10 10:36:18 +0200311LIBYANG_API_DECL LY_ERR ly_errcode(const struct ly_ctx *ctx);
312
313/**
314 * @brief Get human-readable error message for an error code.
315 *
316 * @param[in] err Error code.
Michal Vaskoe4207652023-07-10 14:57:32 +0200317 * @return String error message.
Michal Vaskob5b883c2023-07-10 10:36:18 +0200318 */
319LIBYANG_API_DECL const char *ly_strerrcode(LY_ERR err);
Michal Vasko236cbac2023-02-10 15:45:37 +0100320
321/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200322 * @brief Get the last (thread, context-specific) validation error code.
323 *
324 * This value is set only if ly_errno is #LY_EVALID.
325 *
326 * @param[in] ctx Relative context.
327 * @return Validation error code.
328 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +0100329LIBYANG_API_DECL LY_VECODE ly_vecode(const struct ly_ctx *ctx);
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200330
331/**
Michal Vaskob5b883c2023-07-10 10:36:18 +0200332 * @brief Get human-readable error message for a validation error code.
Radek Krejcid33273d2018-10-25 14:55:52 +0200333 *
Michal Vaskob5b883c2023-07-10 10:36:18 +0200334 * @param[in] vecode Validation error code.
Michal Vaskoe4207652023-07-10 14:57:32 +0200335 * @return String error message.
Radek Krejcid33273d2018-10-25 14:55:52 +0200336 */
Michal Vaskob5b883c2023-07-10 10:36:18 +0200337LIBYANG_API_DECL const char *ly_strvecode(LY_VECODE vecode);
Radek Krejcid33273d2018-10-25 14:55:52 +0200338
339/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200340 * @brief Get the last (thread, context-specific) error message. If the coresponding module defined
341 * a specific error message, it will be used instead the default one.
342 *
343 * Sometimes, the error message is extended with path of the element where the problem is.
Radek Krejci8678fa42020-08-18 16:07:28 +0200344 * The path is available via ::ly_errpath().
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200345 *
346 * @param[in] ctx Relative context.
347 * @return Text of the last error message, empty string if there is no error.
348 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +0100349LIBYANG_API_DECL const char *ly_errmsg(const struct ly_ctx *ctx);
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200350
351/**
Michal Vaskob5b883c2023-07-10 10:36:18 +0200352 * @brief Get the last (thread-specific) error message.
353 *
354 * ::ly_errmsg() should be used instead of this function but this one is useful for getting
355 * errors from functions that do not have any context accessible. Or as a simple unified logging API.
356 *
357 * @return Last generated error message.
358 */
359LIBYANG_API_DECL const char *ly_last_errmsg(void);
360
361/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200362 * @brief Get the last (thread, context-specific) path of the element where was an error.
363 *
Radek Krejci8678fa42020-08-18 16:07:28 +0200364 * The path always corresponds to the error message available via ::ly_errmsg(), so
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200365 * whenever a subsequent error message is printed, the path is erased or rewritten.
366 * The path reflects the type of the processed tree - data path for data tree functions
367 * and schema path in case of schema tree functions. In case of processing YIN schema
368 * or XML data, the path can be just XML path. In such a case, the corresponding
369 * ly_vecode (value 1-3) is set.
370 *
371 * @param[in] ctx Relative context.
372 * @return Path of the error element, empty string if error path does not apply to the last error.
373 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +0100374LIBYANG_API_DECL const char *ly_errpath(const struct ly_ctx *ctx);
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200375
376/**
377 * @brief Get the last (thread, context-specific) error-app-tag if there was a specific one defined
378 * in the module for the last error.
379 *
Radek Krejci8678fa42020-08-18 16:07:28 +0200380 * The app-tag always corresponds to the error message available via ::ly_errmsg(), so
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200381 * whenever a subsequent error message is printed, the app-tag is erased or rewritten.
382 *
383 * @param[in] ctx Relative context.
384 * @return Error-app-tag of the last error, empty string if the error-app-tag does not apply to the last error.
385 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +0100386LIBYANG_API_DECL const char *ly_errapptag(const struct ly_ctx *ctx);
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200387
388/**
389 * @brief Get the first (thread, context-specific) generated error structure.
390 *
391 * @param[in] ctx Relative context.
Radek Krejci572ee602020-09-16 14:35:08 +0200392 * @return The first error structure (can be NULL), do not modify!
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200393 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +0100394LIBYANG_API_DECL struct ly_err_item *ly_err_first(const struct ly_ctx *ctx);
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200395
396/**
Radek Krejci572ee602020-09-16 14:35:08 +0200397 * @brief Get the latest (thread, context-specific) generated error structure.
398 *
399 * @param[in] ctx Relative context.
400 * @return The last error structure (can be NULL), do not modify!
401 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +0100402LIBYANG_API_DECL struct ly_err_item *ly_err_last(const struct ly_ctx *ctx);
Radek Krejci572ee602020-09-16 14:35:08 +0200403
404/**
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200405 * @brief Print the error structure as if just generated.
406 *
Michal Vasko177d0ed2020-11-23 16:43:03 +0100407 * @param[in] ctx Optional context to store the message in.
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200408 * @param[in] eitem Error item structure to print.
409 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +0100410LIBYANG_API_DECL void ly_err_print(const struct ly_ctx *ctx, struct ly_err_item *eitem);
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200411
412/**
413 * @brief Free error structures from a context.
414 *
415 * If \p eitem is not set, free all the error structures.
416 *
417 * @param[in] ctx Relative context.
418 * @param[in] eitem Oldest error structure to remove, optional.
419 */
Jan Kundrátc53a7ec2021-12-09 16:01:19 +0100420LIBYANG_API_DECL void ly_err_clean(struct ly_ctx *ctx, struct ly_err_item *eitem);
Radek Krejci5aeea3a2018-09-05 13:29:36 +0200421
422/** @} errors */
423
424#ifdef __cplusplus
425}
426#endif
427
428#endif /* LY_LOG_H_ */