Skip to content

Commit b4d7fd7

Browse files
committed
log UPDATE log callback ignores log level
1 parent f40ba0d commit b4d7fd7

3 files changed

Lines changed: 20 additions & 13 deletions

File tree

src/log.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -500,13 +500,12 @@ log_stderr_path_line(const char *data_path, const char *schema_path, uint64_t li
500500
/**
501501
* @brief Learn whether a log is a no-operation or must be produced, based on current ly_log_opts.
502502
*
503-
* @param[in] level Message log level to compare to enabled logging level.
504503
* @param[out] will_log Optionally learn whether the log will be printed.
505504
* @param[out] will_store Optionally learn whether the log will be stored.
506505
* @return 1 if the log is a no-operation, 0 otherwise.
507506
*/
508507
static ly_bool
509-
log_is_noop(LY_LOG_LEVEL level, ly_bool *will_log, ly_bool *will_store)
508+
log_is_noop(ly_bool *will_log, ly_bool *will_store)
510509
{
511510
ly_bool lolog, lostore;
512511

@@ -526,7 +525,7 @@ log_is_noop(LY_LOG_LEVEL level, ly_bool *will_log, ly_bool *will_store)
526525
*will_store = lostore;
527526
}
528527

529-
return (level > ATOMIC_LOAD_RELAXED(ly_ll)) || (!lolog && !lostore);
528+
return !lolog && !lostore;
530529
}
531530

532531
/**
@@ -551,7 +550,7 @@ log_vprintf(const struct ly_ctx *ctx, LY_LOG_LEVEL level, LY_ERR err, LY_VECODE
551550
const char *msg;
552551
ly_bool free_strs = 1, lolog, lostore;
553552

554-
if (log_is_noop(level, &lolog, &lostore)) {
553+
if (log_is_noop(&lolog, &lostore)) {
555554
/* do not print or store the message */
556555
goto cleanup;
557556
}
@@ -574,7 +573,7 @@ log_vprintf(const struct ly_ctx *ctx, LY_LOG_LEVEL level, LY_ERR err, LY_VECODE
574573

575574
/* store the error/warning in the context (if we need to store errors internally, it does not matter what are
576575
* the user log options), if the message is not dynamic, it would most likely fail to store (no memory) */
577-
if ((level < LY_LLVRB) && ctx && lostore && dyn_msg) {
576+
if ((level <= ATOMIC_LOAD_RELAXED(ly_ll)) && (level < LY_LLVRB) && ctx && lostore && dyn_msg) {
578577
free_strs = 0;
579578
if (log_store(ctx, level, err, vecode, dyn_msg, data_path, schema_path, line, apptag ? strdup(apptag) : NULL)) {
580579
goto cleanup;
@@ -585,7 +584,7 @@ log_vprintf(const struct ly_ctx *ctx, LY_LOG_LEVEL level, LY_ERR err, LY_VECODE
585584
if (lolog) {
586585
if (log_clb) {
587586
log_clb(level, msg, data_path, schema_path, line);
588-
} else {
587+
} else if (level <= ATOMIC_LOAD_RELAXED(ly_ll)) {
589588
fprintf(stderr, "libyang[%d]: ", level);
590589
fprintf(stderr, "%s", msg);
591590
log_stderr_path_line(data_path, schema_path, line);
@@ -799,10 +798,6 @@ ly_vlog(const struct ly_ctx *ctx, const char *apptag, LY_VECODE code, const char
799798
char *data_path = NULL, *schema_path = NULL;
800799
uint64_t line = 0;
801800

802-
if (log_is_noop(LY_LLERR, NULL, NULL)) {
803-
return;
804-
}
805-
806801
if (ctx) {
807802
ly_vlog_build_path_line(ctx, &data_path, &schema_path, &line);
808803
}
@@ -832,7 +827,7 @@ ly_ext_log(const struct ly_ctx *ctx, const char *plugin_name, LY_LOG_LEVEL level
832827
{
833828
char *plugin_msg;
834829

835-
if (log_is_noop(level, NULL, NULL)) {
830+
if (level > ATOMIC_LOAD_RELAXED(ly_ll)) {
836831
return;
837832
}
838833

@@ -934,7 +929,7 @@ _ly_err_print(const struct ly_ctx *ctx, const struct ly_err_item *eitem, const c
934929

935930
LY_CHECK_ARG_RET(ctx, eitem, );
936931

937-
if (log_is_noop(eitem->level, NULL, NULL)) {
932+
if (eitem->level > ATOMIC_LOAD_RELAXED(ly_ll)) {
938933
return;
939934
}
940935

@@ -953,6 +948,6 @@ _ly_err_print(const struct ly_ctx *ctx, const struct ly_err_item *eitem, const c
953948
LIBYANG_API_DEF void
954949
ly_err_print(const struct ly_ctx *ctx, const struct ly_err_item *eitem)
955950
{
956-
/* String ::ly_err_item.msg cannot be used directly because it may contain the % character */
951+
/* string ::ly_err_item.msg cannot be used directly because it may contain the % character */
957952
_ly_err_print(ctx, eitem, "%s", eitem->msg);
958953
}

src/log.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ typedef enum {
9696
/**
9797
* @brief Set logger verbosity level.
9898
*
99+
* Does not affect the logging callback.
100+
*
99101
* To get the current value, the function must be called twice resetting the level by the received value.
100102
*
101103
* @param[in] level Verbosity level.
@@ -187,6 +189,8 @@ typedef void (*ly_log_clb)(LY_LOG_LEVEL level, const char *msg, const char *data
187189
/**
188190
* @brief Set logger callback.
189191
*
192+
* Is not affected by global log level.
193+
*
190194
* @param[in] clb Logging callback.
191195
*/
192196
LIBYANG_API_DECL void ly_set_log_clb(ly_log_clb clb);

tools/lint/main_ni.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,17 @@ help(int shortout)
238238
static void
239239
libyang_verbclb(LY_LOG_LEVEL level, const char *msg, const char *data_path, const char *schema_path, uint64_t line)
240240
{
241+
LY_LOG_LEVEL sr_ll;
241242
const char *levstr;
242243
char *full_msg = NULL, *aux;
243244

245+
sr_ll = ly_log_level(0);
246+
ly_log_level(sr_ll);
247+
248+
if (level > sr_ll) {
249+
return;
250+
}
251+
244252
switch (level) {
245253
case LY_LLERR:
246254
levstr = "err :";

0 commit comments

Comments
 (0)