@@ -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 */
508507static 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
953948LIBYANG_API_DEF void
954949ly_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}
0 commit comments