ExLLM.Logger (ex_llm v0.5.0)
View SourceUnified logging for ExLLM with automatic context and security features.
This module provides a simple, unified logging interface that combines the simplicity of Elixir's Logger with ExLLM-specific features like context tracking, security redaction, and component filtering.
Usage
Simple logging (like Elixir's Logger):
ExLLM.Logger.info("Model loaded successfully")
ExLLM.Logger.error("Failed to connect", error: reason)
ExLLM.Logger.debug("Processing chunk", size: byte_size(data))
With provider context:
ExLLM.Logger.with_context(provider: :openai, operation: :chat) do
ExLLM.Logger.info("Starting chat request")
# ... do work ...
ExLLM.Logger.info("Chat completed", tokens: 150)
end
Structured logging for specific events:
ExLLM.Logger.log_request(:openai, url, body, headers)
ExLLM.Logger.log_response(:openai, response, duration_ms)
ExLLM.Logger.log_retry(:anthropic, attempt, max_attempts, reason)
Configuration
config :ex_llm,
log_level: :info, # :debug, :info, :warn, :error, :none
log_components: %{
requests: true,
responses: true,
streaming: false,
retries: true,
cache: false,
models: true
},
log_redaction: %{
api_keys: true,
content: false
}
Summary
Functions
Clear all context.
Log a debug message with optional metadata.
Log an error message with optional metadata.
Log an info message with optional metadata.
Log a cache event.
Log a model event.
Log an API request with automatic redaction.
Log an API response.
Log a retry attempt.
Log a streaming event.
Add context that persists for the rest of the process.
Log a warning message with optional metadata.
Set context for all logs within the given function.
Functions
Clear all context.
Log a debug message with optional metadata.
Log an error message with optional metadata.
Log an info message with optional metadata.
Log a cache event.
Log a model event.
Log an API request with automatic redaction.
Log an API response.
Log a retry attempt.
Log a streaming event.
Add context that persists for the rest of the process.
Log a warning message with optional metadata.
Set context for all logs within the given function.
Examples
ExLLM.Logger.with_context(provider: :openai, operation: :chat) do
ExLLM.Logger.info("Starting request")
# All logs in here will include provider and operation
end