move verbosity.rs -> logging.rs
This commit is contained in:
parent
4beda8850f
commit
0087d2848a
3 changed files with 77 additions and 38 deletions
|
|
@ -8,10 +8,10 @@ pub extern crate nixide_sys as sys;
|
||||||
|
|
||||||
pub(crate) mod errors;
|
pub(crate) mod errors;
|
||||||
mod init;
|
mod init;
|
||||||
|
pub mod logging;
|
||||||
mod nix_settings;
|
mod nix_settings;
|
||||||
mod stdext;
|
mod stdext;
|
||||||
pub(crate) mod util;
|
pub(crate) mod util;
|
||||||
mod verbosity;
|
|
||||||
mod version;
|
mod version;
|
||||||
|
|
||||||
#[cfg(feature = "exprs")]
|
#[cfg(feature = "exprs")]
|
||||||
|
|
@ -23,7 +23,6 @@ mod store;
|
||||||
|
|
||||||
pub use errors::{NixError, NixideError, NixideResult};
|
pub use errors::{NixError, NixideError, NixideResult};
|
||||||
pub use nix_settings::{get_global_setting, set_global_setting};
|
pub use nix_settings::{get_global_setting, set_global_setting};
|
||||||
pub use verbosity::{NixVerbosity, set_verbosity};
|
|
||||||
pub use version::NixVersion;
|
pub use version::NixVersion;
|
||||||
|
|
||||||
#[cfg(feature = "exprs")]
|
#[cfg(feature = "exprs")]
|
||||||
|
|
|
||||||
76
nixide/src/logging.rs
Normal file
76
nixide/src/logging.rs
Normal file
|
|
@ -0,0 +1,76 @@
|
||||||
|
use crate::errors::ErrorContext;
|
||||||
|
use crate::stdext::AsCPtr as _;
|
||||||
|
use crate::sys;
|
||||||
|
use crate::util::wrap;
|
||||||
|
use crate::util::wrappers::AsInnerPtr as _;
|
||||||
|
|
||||||
|
pub use sys::NixVerbosity;
|
||||||
|
|
||||||
|
/// Sets the verbosity level.
|
||||||
|
///
|
||||||
|
/// **This function should never fail!**
|
||||||
|
/// A panic would indicate a bug in nixide itself.
|
||||||
|
///
|
||||||
|
/// # Nix C++ API Internals
|
||||||
|
///
|
||||||
|
/// ```cpp
|
||||||
|
/// 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);
|
||||||
|
/// } catch (...) {
|
||||||
|
/// return nix_context_error(context);
|
||||||
|
/// }
|
||||||
|
/// return NIX_OK;
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
pub fn set_verbosity(level: NixVerbosity) {
|
||||||
|
wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||||
|
sys::nix_set_verbosity(ctx.as_ptr(), level);
|
||||||
|
})
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The log formats `libnix` can output.
|
||||||
|
///
|
||||||
|
/// # Nix C++ API Internals
|
||||||
|
///
|
||||||
|
/// Defined in `/libmain/include/nix/main/loggers.hh`.
|
||||||
|
///
|
||||||
|
pub enum LogFormat {
|
||||||
|
Raw,
|
||||||
|
RawWithLogs,
|
||||||
|
InternalJSON,
|
||||||
|
Bar,
|
||||||
|
BarWithLogs,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToString for LogFormat {
|
||||||
|
fn to_string(&self) -> String {
|
||||||
|
match self {
|
||||||
|
LogFormat::Raw => "raw".to_owned(),
|
||||||
|
LogFormat::RawWithLogs => "raw-with-logs".to_owned(),
|
||||||
|
LogFormat::InternalJSON => "internal-json".to_owned(),
|
||||||
|
LogFormat::Bar => "bar".to_owned(),
|
||||||
|
LogFormat::BarWithLogs => "bar-with-logs".to_owned(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Configure the global (default) logger's output format.
|
||||||
|
///
|
||||||
|
/// **This function should never fail!**
|
||||||
|
/// A panic would indicate a nix's `enum LogFormat` has been
|
||||||
|
/// modified without nixide updating to account for this.
|
||||||
|
///
|
||||||
|
pub fn set_log_format(format: LogFormat) {
|
||||||
|
wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||||
|
sys::nix_set_log_format(ctx.as_ptr(), format.to_string().as_c_ptr().unwrap());
|
||||||
|
})
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
use crate::errors::ErrorContext;
|
|
||||||
use crate::sys;
|
|
||||||
use crate::util::wrap;
|
|
||||||
use crate::util::wrappers::AsInnerPtr as _;
|
|
||||||
|
|
||||||
pub use sys::NixVerbosity;
|
|
||||||
|
|
||||||
/// Sets the verbosity level.
|
|
||||||
///
|
|
||||||
/// **This function should never fail!**
|
|
||||||
/// A panic would indicate a bug in nixide itself.
|
|
||||||
///
|
|
||||||
/// # Nix C++ API Internals
|
|
||||||
///
|
|
||||||
/// ```cpp
|
|
||||||
/// 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);
|
|
||||||
/// } catch (...) {
|
|
||||||
/// return nix_context_error(context);
|
|
||||||
/// }
|
|
||||||
/// return NIX_OK;
|
|
||||||
/// }
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
pub fn set_verbosity(level: NixVerbosity) {
|
|
||||||
wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
|
||||||
sys::nix_set_verbosity(ctx.as_ptr(), level);
|
|
||||||
})
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue