Make logging generic across backends and simplify the code
This commit is contained in:
parent
d3fe24a512
commit
1db502bc1a
7 changed files with 253 additions and 100 deletions
38
src/lib.rs
38
src/lib.rs
|
|
@ -1,26 +1,20 @@
|
|||
#![allow(clippy::uninlined_format_args)]
|
||||
#![cfg_attr(test, feature(test))]
|
||||
|
||||
mod common_logging;
|
||||
mod error;
|
||||
mod ggml_logging_hook;
|
||||
mod standalone;
|
||||
mod utilities;
|
||||
mod whisper_ctx;
|
||||
mod whisper_ctx_wrapper;
|
||||
mod whisper_grammar;
|
||||
mod whisper_logging_hook;
|
||||
mod whisper_params;
|
||||
mod whisper_state;
|
||||
#[cfg(feature = "whisper-cpp-log")]
|
||||
mod whisper_sys_log;
|
||||
#[cfg(feature = "whisper-cpp-tracing")]
|
||||
mod whisper_sys_tracing;
|
||||
|
||||
#[cfg(any(feature = "whisper-cpp-log", feature = "whisper-cpp-tracing"))]
|
||||
static LOG_TRAMPOLINE_INSTALL: Once = Once::new();
|
||||
|
||||
pub use error::WhisperError;
|
||||
pub use standalone::*;
|
||||
#[cfg(any(feature = "whisper-cpp-log", feature = "whisper-cpp-tracing"))]
|
||||
use std::sync::Once;
|
||||
pub use utilities::*;
|
||||
pub use whisper_ctx::DtwMode;
|
||||
pub use whisper_ctx::DtwModelPreset;
|
||||
|
|
@ -33,10 +27,6 @@ pub use whisper_params::{FullParams, SamplingStrategy, SegmentCallbackData};
|
|||
#[cfg(feature = "raw-api")]
|
||||
pub use whisper_rs_sys;
|
||||
pub use whisper_state::WhisperState;
|
||||
#[cfg(feature = "whisper-cpp-log")]
|
||||
pub use whisper_sys_log::install_whisper_log_trampoline;
|
||||
#[cfg(feature = "whisper-cpp-tracing")]
|
||||
pub use whisper_sys_tracing::install_whisper_tracing_trampoline;
|
||||
|
||||
pub type WhisperSysContext = whisper_rs_sys::whisper_context;
|
||||
pub type WhisperSysState = whisper_rs_sys::whisper_state;
|
||||
|
|
@ -53,3 +43,25 @@ pub type DtwAhead = whisper_rs_sys::whisper_ahead;
|
|||
|
||||
/// The version of whisper.cpp that whisper-rs was linked with.
|
||||
pub static WHISPER_CPP_VERSION: &str = env!("WHISPER_CPP_VERSION");
|
||||
|
||||
/// Redirect all whisper.cpp and GGML logs to logging hooks installed by whisper-rs.
|
||||
///
|
||||
/// This will stop most logs from being output to stdout/stderr and will bring them into
|
||||
/// `log` or `tracing`, if the `log_backend` or `tracing_backend` features, respectively,
|
||||
/// are enabled. If neither is enabled, this will essentially disable logging, as they won't
|
||||
/// be output anywhere.
|
||||
///
|
||||
/// Note whisper.cpp and GGML do not reliably follow Rust logging conventions.
|
||||
/// Use your logging crate's configuration to control how these logs will be output.
|
||||
/// whisper-rs does not currently output any logs, but this may change in the future.
|
||||
/// You should configure by module path and use `whisper_rs::ggml_logging_hook`,
|
||||
/// and/or `whisper_rs::whisper_logging_hook`, to avoid possibly ignoring useful
|
||||
/// `whisper-rs` logs in the future.
|
||||
///
|
||||
/// Safe to call multiple times. Only has an effect the first time.
|
||||
/// (note this means installing your own logging handlers with unsafe functions after this call
|
||||
/// is permanent and cannot be undone)
|
||||
pub fn install_logging_hooks() {
|
||||
crate::whisper_logging_hook::install_whisper_logging_hook();
|
||||
crate::ggml_logging_hook::install_ggml_logging_hook();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue