mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 03:56:01 +01:00
Merge pull request #14058 from DeterminateSystems/upstream-RossComputerGuy/feat/expose-logfmt
C API: add log format and verbosity functions
This commit is contained in:
commit
b0431a76f5
4 changed files with 59 additions and 0 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
#include "nix_api_util_internal.h"
|
#include "nix_api_util_internal.h"
|
||||||
|
|
||||||
#include "nix/main/plugin.hh"
|
#include "nix/main/plugin.hh"
|
||||||
|
#include "nix/main/loggers.hh"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
|
|
@ -17,4 +18,16 @@ nix_err nix_init_plugins(nix_c_context * context)
|
||||||
NIXC_CATCH_ERRS
|
NIXC_CATCH_ERRS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nix_err nix_set_log_format(nix_c_context * context, const char * format)
|
||||||
|
{
|
||||||
|
if (context)
|
||||||
|
context->last_err_code = NIX_OK;
|
||||||
|
if (format == nullptr)
|
||||||
|
return nix_set_err_msg(context, NIX_ERR_UNKNOWN, "Log format is null");
|
||||||
|
try {
|
||||||
|
nix::setLogFormat(format);
|
||||||
|
}
|
||||||
|
NIXC_CATCH_ERRS
|
||||||
|
}
|
||||||
|
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,14 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
nix_err nix_init_plugins(nix_c_context * context);
|
nix_err nix_init_plugins(nix_c_context * context);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets the log format
|
||||||
|
*
|
||||||
|
* @param[out] context Optional, stores error information
|
||||||
|
* @param[in] format The string name of the format.
|
||||||
|
*/
|
||||||
|
nix_err nix_set_log_format(nix_c_context * context, const char * format);
|
||||||
|
|
||||||
// cffi end
|
// cffi end
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -159,4 +159,16 @@ nix_err call_nix_get_string_callback(const std::string str, nix_get_string_callb
|
||||||
return NIX_OK;
|
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"
|
} // extern "C"
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,24 @@ enum nix_err {
|
||||||
|
|
||||||
typedef enum nix_err 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.
|
* @brief This object stores error state.
|
||||||
* @struct nix_c_context
|
* @struct nix_c_context
|
||||||
|
|
@ -327,6 +345,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);
|
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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue