From 77db5e404aba8eae39ad36dbab5423c6b350dbd1 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 30 Jul 2026 03:24:37 +0000 Subject: [PATCH] refactor(rust): move debug renderer into core Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com> --- litellm-rust/Cargo.lock | 2 +- litellm-rust/README.md | 7 +++---- litellm-rust/crates/ai-gateway/Cargo.toml | 1 - .../crates/ai-gateway/src/integrations/logging/mod.rs | 7 ------- .../crates/ai-gateway/src/integrations/mod.rs | 1 - litellm-rust/crates/ai-gateway/src/main.rs | 8 ++++++-- litellm-rust/crates/core/CLAUDE.md | 3 +-- litellm-rust/crates/core/Cargo.toml | 1 + .../src/integrations => core/src}/logging/console.rs | 11 ++--------- litellm-rust/crates/core/src/logging/mod.rs | 1 + litellm-rust/crates/python-bridge/src/logging.rs | 3 +-- 11 files changed, 16 insertions(+), 29 deletions(-) delete mode 100644 litellm-rust/crates/ai-gateway/src/integrations/logging/mod.rs rename litellm-rust/crates/{ai-gateway/src/integrations => core/src}/logging/console.rs (96%) diff --git a/litellm-rust/Cargo.lock b/litellm-rust/Cargo.lock index a5aa10d5e73..ed5bc49b532 100644 --- a/litellm-rust/Cargo.lock +++ b/litellm-rust/Cargo.lock @@ -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", diff --git a/litellm-rust/README.md b/litellm-rust/README.md index 2bf0f1e8162..06afda7774a 100644 --- a/litellm-rust/README.md +++ b/litellm-rust/README.md @@ -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`. diff --git a/litellm-rust/crates/ai-gateway/Cargo.toml b/litellm-rust/crates/ai-gateway/Cargo.toml index 4dbfa9e85f1..541beabe170 100644 --- a/litellm-rust/crates/ai-gateway/Cargo.toml +++ b/litellm-rust/crates/ai-gateway/Cargo.toml @@ -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 } diff --git a/litellm-rust/crates/ai-gateway/src/integrations/logging/mod.rs b/litellm-rust/crates/ai-gateway/src/integrations/logging/mod.rs deleted file mode 100644 index cb7fcb93592..00000000000 --- a/litellm-rust/crates/ai-gateway/src/integrations/logging/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -pub mod console; - -pub use litellm_core::logging::{ - BodySnapshot, ErrorEventInput, LogEvent, LogSink, ProviderErrorEvent, ProviderRequestEvent, - ProviderResponseEvent, ProviderStreamCompletedEvent, ProviderStreamStartedEvent, - RequestEventInput, ResponseBody, ResponseEventInput, -}; diff --git a/litellm-rust/crates/ai-gateway/src/integrations/mod.rs b/litellm-rust/crates/ai-gateway/src/integrations/mod.rs index 07253ecc7f7..c62f1821ef8 100644 --- a/litellm-rust/crates/ai-gateway/src/integrations/mod.rs +++ b/litellm-rust/crates/ai-gateway/src/integrations/mod.rs @@ -9,5 +9,4 @@ pub mod custom_guardrail; pub mod custom_logger; pub mod litellm_python_proxy_api; -pub mod logging; pub mod types; diff --git a/litellm-rust/crates/ai-gateway/src/main.rs b/litellm-rust/crates/ai-gateway/src/main.rs index e08bd283058..6ddb5c21646 100644 --- a/litellm-rust/crates/ai-gateway/src/main.rs +++ b/litellm-rust/crates/ai-gateway/src/main.rs @@ -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()); diff --git a/litellm-rust/crates/core/CLAUDE.md b/litellm-rust/crates/core/CLAUDE.md index 397e1369a1f..7e0ad6f4d90 100644 --- a/litellm-rust/crates/core/CLAUDE.md +++ b/litellm-rust/crates/core/CLAUDE.md @@ -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. diff --git a/litellm-rust/crates/core/Cargo.toml b/litellm-rust/crates/core/Cargo.toml index d53f6d820c7..51700143509 100644 --- a/litellm-rust/crates/core/Cargo.toml +++ b/litellm-rust/crates/core/Cargo.toml @@ -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 } diff --git a/litellm-rust/crates/ai-gateway/src/integrations/logging/console.rs b/litellm-rust/crates/core/src/logging/console.rs similarity index 96% rename from litellm-rust/crates/ai-gateway/src/integrations/logging/console.rs rename to litellm-rust/crates/core/src/logging/console.rs index 89884829acd..1046a1ae31a 100644 --- a/litellm-rust/crates/ai-gateway/src/integrations/logging/console.rs +++ b/litellm-rust/crates/core/src/logging/console.rs @@ -40,13 +40,6 @@ impl ConsoleDebugHook { } } -pub fn hook_from_env() -> Option> { - std::env::var("LITELLM_LOG") - .ok() - .filter(|value| value.eq_ignore_ascii_case("DEBUG")) - .map(|_| Arc::new(ConsoleDebugHook::from_env()) as Arc) -} - pub fn hook(enabled: bool) -> Option> { enabled.then(|| Arc::new(ConsoleDebugHook::from_env()) as Arc) } @@ -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>>); impl Write for Buffer { diff --git a/litellm-rust/crates/core/src/logging/mod.rs b/litellm-rust/crates/core/src/logging/mod.rs index 1525b606eff..900b10fd065 100644 --- a/litellm-rust/crates/core/src/logging/mod.rs +++ b/litellm-rust/crates/core/src/logging/mod.rs @@ -1,5 +1,6 @@ mod redaction; +pub mod console; pub mod events; pub mod http; pub mod stream; diff --git a/litellm-rust/crates/python-bridge/src/logging.rs b/litellm-rust/crates/python-bridge/src/logging.rs index cbc736b9719..92460f451e6 100644 --- a/litellm-rust/crates/python-bridge/src/logging.rs +++ b/litellm-rust/crates/python-bridge/src/logging.rs @@ -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> { console_hook(enabled)