Skip to main content

llama_cpp_bindings/
log_options.rs

1/// Options to configure how llama.cpp logs are intercepted.
2#[derive(Default, Debug, Clone)]
3pub struct LogOptions {
4    pub disabled: bool,
5    pub demote_info_to_debug: bool,
6}
7
8impl LogOptions {
9    /// If enabled, logs are sent to tracing. If disabled, all logs are suppressed. Default is for
10    /// logs to be sent to tracing.
11    #[must_use]
12    pub const fn with_logs_enabled(mut self, enabled: bool) -> Self {
13        self.disabled = !enabled;
14
15        self
16    }
17
18    /// When enabled, llama.cpp and ggml INFO logs are demoted to DEBUG tracing level. WARN and
19    /// ERROR logs retain their original severity. This suppresses verbose informational output
20    /// under a typical INFO-level subscriber while keeping important diagnostics visible.
21    /// All demoted logs remain available via `RUST_LOG=debug`.
22    #[must_use]
23    pub const fn with_demote_info_to_debug(mut self, demote: bool) -> Self {
24        self.demote_info_to_debug = demote;
25
26        self
27    }
28}
29
30#[cfg(test)]
31mod tests {
32    use super::LogOptions;
33
34    #[test]
35    fn builder_chain_sets_both_flags() {
36        let options = LogOptions::default()
37            .with_logs_enabled(false)
38            .with_demote_info_to_debug(true);
39
40        assert!(options.disabled);
41        assert!(options.demote_info_to_debug);
42    }
43}