Implementation:BerriAI Litellm Logging Setup
| Attribute | Value |
|---|---|
| Sources | litellm/_logging.py |
| Domains | Logging, Observability, Configuration |
| last_updated | 2026-02-15 16:00 GMT |
Overview
The Logging Setup module initializes and configures the Python logging infrastructure for LiteLLM, providing three named loggers, a JSON formatter, and utility functions for controlling log verbosity.
Description
This module is executed at import time and sets up the foundational logging subsystem for the entire LiteLLM library. It creates three named loggers:
verbose_logger--"LiteLLM"(general library logging)verbose_router_logger--"LiteLLM Router"(router/load-balancing logging)verbose_proxy_logger--"LiteLLM Proxy"(proxy server logging)
The module reads environment variables to configure behavior:
LITELLM_LOG-- sets the log level (default:DEBUG)JSON_LOGS-- when truthy, applies theJsonFormatterfor structured JSON output
The JsonFormatter class produces JSON log lines with ISO 8601 timestamps, log level, message, and optional stacktrace. It also attempts to parse embedded JSON or Python dict representations in log messages, promoting their fields to top-level JSON keys.
The module suppresses noisy third-party loggers (httpx, APScheduler) by setting them to WARNING level. Helper functions provide runtime control: _turn_on_debug(), _disable_debugging(), _enable_debugging(), _turn_on_json(), and _is_debugging_on().
Usage
Import the loggers directly for use throughout the LiteLLM codebase:
from litellm._logging import verbose_logger
Code Reference
Source Location
/litellm/_logging.py (352 lines)
Key Symbols
| Symbol | Type | Description |
|---|---|---|
verbose_logger |
logging.Logger |
Main LiteLLM logger |
verbose_router_logger |
logging.Logger |
Router subsystem logger |
verbose_proxy_logger |
logging.Logger |
Proxy server logger |
JsonFormatter |
class(Formatter) |
Formats log records as JSON |
_turn_on_debug |
def _turn_on_debug() -> None |
Sets all loggers to DEBUG level |
_turn_on_json |
def _turn_on_json() -> None |
Switches all loggers to JSON formatting |
_is_debugging_on |
def _is_debugging_on() -> bool |
Returns whether DEBUG logging is active |
_get_uvicorn_json_log_config |
def _get_uvicorn_json_log_config() -> dict |
Generates uvicorn log_config dict for JSON mode |
print_verbose |
def print_verbose(print_statement) -> None |
Legacy verbose printing (deprecated) |
Import
from litellm._logging import verbose_logger, verbose_proxy_logger, verbose_router_logger
I/O Contract
Inputs (Environment Variables)
| Variable | Type | Description |
|---|---|---|
LITELLM_LOG |
str |
Log level string (e.g., "DEBUG", "INFO")
|
JSON_LOGS |
str |
When truthy, enables JSON log formatting |
Outputs
| Export | Type | Description |
|---|---|---|
verbose_logger |
logging.Logger |
Pre-configured logger for general LiteLLM use |
verbose_router_logger |
logging.Logger |
Pre-configured logger for router subsystem |
verbose_proxy_logger |
logging.Logger |
Pre-configured logger for proxy server |
ALL_LOGGERS |
list[logging.Logger] |
List of all loggers including root |
Usage Examples
from litellm._logging import verbose_logger, _turn_on_debug, _is_debugging_on
# Standard logging
verbose_logger.info("Processing request for model: %s", model_name)
# Enable debug logging at runtime
_turn_on_debug()
# Check if debugging is active
if _is_debugging_on():
verbose_logger.debug("Detailed parameter dump: %s", params)
# JSON log output example (when JSON_LOGS=True)
# {"message": "Processing request for model: gpt-4", "level": "INFO", "timestamp": "2026-02-15T16:00:00"}
Related Pages
- BerriAI_Litellm_Service_Logger - uses these loggers for service health monitoring
- BerriAI_Litellm_Logging_Worker - background logging worker that uses verbose_logger
- BerriAI_Litellm_Logging_Callback_Manager - manages callback registration and invocation