refactor(rust): move debug renderer into core

Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com>
This commit is contained in:
Devin AI 2026-07-30 03:24:37 +00:00
parent d857e6ab0f
commit 77db5e404a
11 changed files with 16 additions and 29 deletions

View file

@ -1229,7 +1229,6 @@ version = "0.1.0"
dependencies = [
"axum",
"base64",
"colored_json",
"futures-channel",
"futures-util",
"litellm-core",
@ -1255,6 +1254,7 @@ dependencies = [
"aws-smithy-runtime-api",
"aws-types",
"bytes",
"colored_json",
"futures-util",
"rand 0.8.7",
"reqwest",

View file

@ -47,10 +47,9 @@ function per top-level route, mirroring the core entrypoints.
## Provider debug logging
The typed provider debug contract and `CallLogger` live in
`crates/core/src/logging/`; the gateway renderer and activation live in
`crates/ai-gateway/src/integrations/logging/`. Python enables the injected sink
with `litellm._turn_on_debug()`, while the standalone gateway uses
The typed provider debug contract, `CallLogger`, and console renderer live in
`crates/core/src/logging/`. The gateway and Python bridge own activation:
Python enables the injected sink with `litellm._turn_on_debug()`, while the standalone gateway uses
`LITELLM_LOG=DEBUG`. `JSON_LOGS=true` selects compact JSON; terminal pretty
output honors `NO_COLOR`.

View file

@ -24,7 +24,6 @@ tokio-tungstenite.workspace = true
futures-util.workspace = true
serde_json.workspace = true
base64.workspace = true
colored_json.workspace = true
axum = { workspace = true, features = ["ws"], optional = true }
serde.workspace = true
subtle = { workspace = true, optional = true }

View file

@ -1,7 +0,0 @@
pub mod console;
pub use litellm_core::logging::{
BodySnapshot, ErrorEventInput, LogEvent, LogSink, ProviderErrorEvent, ProviderRequestEvent,
ProviderResponseEvent, ProviderStreamCompletedEvent, ProviderStreamStartedEvent,
RequestEventInput, ResponseBody, ResponseEventInput,
};

View file

@ -9,5 +9,4 @@
pub mod custom_guardrail;
pub mod custom_logger;
pub mod litellm_python_proxy_api;
pub mod logging;
pub mod types;

View file

@ -18,9 +18,9 @@ use litellm_core::router::{Deployment, LiteLLMParams, Router};
use litellm_ai_gateway::integrations::custom_logger::CustomLogger;
use litellm_ai_gateway::integrations::litellm_python_proxy_api::LiteLLMPythonProxyAPILogger;
use litellm_ai_gateway::integrations::logging::console::hook_from_env;
#[cfg(feature = "python-config")]
use litellm_ai_gateway::python;
use litellm_core::logging::console::hook;
/// Bind to localhost by default so the gateway is not a public, unauthenticated
/// provider proxy out of the box. Override with `HOST` (e.g. `0.0.0.0`).
@ -73,7 +73,11 @@ async fn main() {
master_key,
loggers: Arc::new(loggers),
realtime_pool,
logging_sink: hook_from_env(),
logging_sink: std::env::var("LITELLM_LOG")
.ok()
.is_some_and(|value| value.eq_ignore_ascii_case("DEBUG"))
.then(|| hook(true))
.flatten(),
};
let host = std::env::var("HOST").unwrap_or_else(|_| DEFAULT_HOST.to_string());

View file

@ -27,8 +27,7 @@ Not allowed:
- 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 host-injected debug log sink is the exception; it receives redacted events
without env reads, I/O, or callback dispatch in core.
- The logging module owns the debug sink, renderer env vars, and stderr output.
- Provider-specific branching that belongs in `providers`.
- Panics for user/provider-controlled input.

View file

@ -13,6 +13,7 @@ futures-util.workspace = true
url.workspace = true
serde.workspace = true
serde_json.workspace = true
colored_json.workspace = true
thiserror.workspace = true
sha2.workspace = true
aws-config = { version = "1.9.0", default-features = false, features = ["rustls", "rt-tokio"], optional = true }

View file

@ -40,13 +40,6 @@ impl ConsoleDebugHook {
}
}
pub fn hook_from_env() -> Option<Arc<dyn LogSink>> {
std::env::var("LITELLM_LOG")
.ok()
.filter(|value| value.eq_ignore_ascii_case("DEBUG"))
.map(|_| Arc::new(ConsoleDebugHook::from_env()) as Arc<dyn LogSink>)
}
pub fn hook(enabled: bool) -> Option<Arc<dyn LogSink>> {
enabled.then(|| Arc::new(ConsoleDebugHook::from_env()) as Arc<dyn LogSink>)
}
@ -150,9 +143,9 @@ mod tests {
use serde_json::json;
use super::*;
use litellm_core::logging::{LogEvent, ProviderRequestEvent};
use crate::logging::ProviderRequestEvent;
use super::*;
struct Buffer(Arc<Mutex<Vec<u8>>>);
impl Write for Buffer {

View file

@ -1,5 +1,6 @@
mod redaction;
pub mod console;
pub mod events;
pub mod http;
pub mod stream;

View file

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