1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-08 19:46:02 +01:00

libutil-c: add nix_set_verbosity function

This commit is contained in:
Tristan Ross 2025-09-23 12:53:43 -07:00
parent cf595b81d5
commit bb6a4dccdf
No known key found for this signature in database
GPG key ID: 58BB826E9F8688F4
2 changed files with 38 additions and 0 deletions

View file

@ -159,4 +159,16 @@ nix_err call_nix_get_string_callback(const std::string str, nix_get_string_callb
return NIX_OK;
}
nix_err nix_set_verbosity(nix_c_context * context, nix_verbosity level)
{
if (context)
context->last_err_code = NIX_OK;
if (level > NIX_LVL_VOMIT || level < NIX_LVL_ERROR)
return nix_set_err_msg(context, NIX_ERR_UNKNOWN, "Invalid verbosity level");
try {
nix::verbosity = static_cast<nix::Verbosity>(level);
}
NIXC_CATCH_ERRS
}
} // extern "C"

View file

@ -102,6 +102,24 @@ enum nix_err {
typedef enum nix_err nix_err;
/**
* @brief Verbosity level
*
* @note This should be kept in sync with the C++ implementation (nix::Verbosity)
*/
enum nix_verbosity {
NIX_LVL_ERROR = 0,
NIX_LVL_WARN,
NIX_LVL_NOTICE,
NIX_LVL_INFO,
NIX_LVL_TALKATIVE,
NIX_LVL_CHATTY,
NIX_LVL_DEBUG,
NIX_LVL_VOMIT,
};
typedef enum nix_verbosity nix_verbosity;
/**
* @brief This object stores error state.
* @struct nix_c_context
@ -316,6 +334,14 @@ nix_err nix_set_err_msg(nix_c_context * context, nix_err err, const char * msg);
*/
void nix_clear_err(nix_c_context * context);
/**
* @brief Sets the verbosity level
*
* @param[out] context Optional, additional error context.
* @param[in] level Verbosity level
*/
nix_err nix_set_verbosity(nix_c_context * context, nix_verbosity level);
/**
* @}
*/