refactor(rust): simplify debug sink construction
Some checks are pending
LiteLLM Rust / rustfmt, clippy, test (push) Waiting to run

Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com>
This commit is contained in:
Devin AI 2026-07-30 04:08:20 +00:00
parent 77db5e404a
commit d5753f2d90
4 changed files with 10 additions and 17 deletions

View file

@ -68,16 +68,15 @@ async fn main() {
);
}
let debug_logging = std::env::var("LITELLM_LOG")
.ok()
.is_some_and(|value| value.eq_ignore_ascii_case("DEBUG"));
let state = AppState {
router,
master_key,
loggers: Arc::new(loggers),
realtime_pool,
logging_sink: std::env::var("LITELLM_LOG")
.ok()
.is_some_and(|value| value.eq_ignore_ascii_case("DEBUG"))
.then(|| hook(true))
.flatten(),
logging_sink: hook(debug_logging),
};
let host = std::env::var("HOST").unwrap_or_else(|_| DEFAULT_HOST.to_string());

View file

@ -26,8 +26,9 @@ Not allowed:
- Filesystem, database, or cache access.
- Config file reading or rollout state; the host resolves those and passes them
in. Env reads are limited to credential fallback in a route's `prepare.rs`.
- Logging callbacks, tracing spans, spend writes, or customer callbacks.
- The logging module owns the debug sink, renderer env vars, and stderr output.
- Logging callbacks, tracing spans, spend writes, or customer callbacks, except
the `logging` module's debug sink, which owns the renderer env vars and stderr
output.
- Provider-specific branching that belongs in `providers`.
- Panics for user/provider-controlled input.

View file

@ -7,6 +7,7 @@ use litellm_ai_gateway::io::audio_transcription::{
use litellm_ai_gateway::io::ocr::{OcrRequest, ocr as run_ocr};
use litellm_ai_gateway::io::responses_ws::ResponsesWebSocketConnection as RustResponsesWebSocketConnection;
use litellm_core::error::CoreError;
use litellm_core::logging::console::hook;
use litellm_core::messages::messages as run_messages;
use litellm_core::messages::types::{AnthropicMessagesResponse, MessagesRequest};
use pyo3::exceptions::{PyRuntimeError, PyValueError};
@ -15,7 +16,6 @@ use pyo3::types::{PyAny, PyDict};
use serde_json::{Map, Value};
mod gil;
mod logging;
type MarshaledOcrInputs = (
Value,
@ -393,7 +393,7 @@ fn messages(
extra_headers,
timeout,
litellm_call_id: None,
logging_sink: logging::hook(debug),
logging_sink: hook(debug),
}))
});
@ -430,7 +430,7 @@ fn amessages(
extra_headers,
timeout,
litellm_call_id: None,
logging_sink: logging::hook(debug),
logging_sink: hook(debug),
})
.await
.map_err(core_error_to_pyerr)?;

View file

@ -1,7 +0,0 @@
use std::sync::Arc;
use litellm_core::logging::{LogSink, console::hook as console_hook};
pub fn hook(enabled: bool) -> Option<Arc<dyn LogSink>> {
console_hook(enabled)
}