Skip to content

Logging

The Strands SDK provides logging infrastructure to give visibility into its operations.

Strands SDK uses Python’s standard logging module. The SDK implements a straightforward logging approach:

  1. Module-level Loggers: Each module creates its own logger using logging.getLogger(__name__), following Python best practices for hierarchical logging.

  2. Root Logger: All loggers are children of the “strands” root logger, making it easy to configure logging for the entire SDK.

  3. Default Behavior: By default, the SDK doesn’t configure any handlers or log levels, allowing you to integrate it with your application’s logging configuration.

To enable logging for the Strands Agents SDK, you can configure the “strands” logger:

import logging
# Configure the root strands logger
logging.getLogger("strands").setLevel(logging.DEBUG)
# Add a handler to see the logs
logging.basicConfig(
format="%(levelname)s | %(name)s | %(message)s",
handlers=[logging.StreamHandler()]
)

The Strands Agents SDK uses standard log levels:

  • DEBUG: Detailed operational information for troubleshooting. Extensively used for tool registration, discovery, configuration, and execution flows.

  • INFO: General informational messages. Currently not used.

  • WARNING: Potential issues that don’t prevent operation, such as validation failures, specification errors, and compatibility warnings.

  • ERROR: Significant problems that prevent specific operations from completing successfully, such as execution failures and handler errors.

  • CRITICAL: Reserved for catastrophic failures.

The Strands Agents SDK logs information in several key areas. Let’s look at what kinds of logs you might see when using the following example agent with a calculator tool:

from strands import Agent
from strands.tools.calculator import calculator
# Create an agent with the calculator tool
agent = Agent(tools=[calculator])
result = agent("What is 125 * 37?")

When running this code with logging enabled, you’ll see logs from different components of the SDK as the agent processes the request, calls the calculator tool, and generates a response.

Logs related to tool discovery, registration, and execution:

# Tool registration
DEBUG | strands.tools.registry | tool_name=<calculator> | registering tool
DEBUG | strands.tools.registry | tool_name=<calculator>, tool_type=<function>, is_dynamic=<False> | registering tool
DEBUG | strands.tools.registry | tool_name=<calculator> | loaded tool config
DEBUG | strands.tools.registry | tool_count=<1> | tools configured
# Tool discovery
DEBUG | strands.tools.registry | tools_dir=</path/to/tools> | found tools directory
DEBUG | strands.tools.registry | tools_dir=</path/to/tools> | scanning
DEBUG | strands.tools.registry | tool_modules=<['calculator', 'weather']> | discovered
# Tool validation
WARNING | strands.tools.registry | tool_name=<invalid_tool> | spec validation failed | Missing required fields in tool spec: description
DEBUG | strands.tools.registry | tool_name=<calculator> | loaded dynamic tool config
# Tool execution
DEBUG | strands.event_loop.event_loop | tool_use=<calculator_tool_use_id> | streaming
# Tool hot reloading
DEBUG | strands.tools.registry | tool_name=<calculator> | searching directories for tool
DEBUG | strands.tools.registry | tool_name=<calculator> | reloading tool
DEBUG | strands.tools.registry | tool_name=<calculator> | successfully reloaded tool

Logs related to the event loop processing:

ERROR | strands.event_loop.error_handler | an exception occurred in event_loop_cycle | ContextWindowOverflowException
DEBUG | strands.event_loop.error_handler | message_index=<5> | found message with tool results at index

Logs related to interactions with foundation models:

DEBUG | strands.models.bedrock | config=<{'model_id': 'us.anthropic.claude-4-sonnet-20250219-v1:0'}> | initializing
WARNING | strands.models.bedrock | bedrock threw context window overflow error
DEBUG | strands.models.bedrock | Found blocked output guardrail. Redacting output.

You can configure logging for specific modules within the SDK:

import logging
# Enable DEBUG logs for the tool registry only
logging.getLogger("strands.tools.registry").setLevel(logging.DEBUG)
# Set WARNING level for model interactions
logging.getLogger("strands.models").setLevel(logging.WARNING)

You can add custom handlers to process logs in different ways:

import logging
import json
class JsonFormatter(logging.Formatter):
def format(self, record):
log_data = {
"timestamp": self.formatTime(record),
"level": record.levelname,
"name": record.name,
"message": record.getMessage()
}
return json.dumps(log_data)
# Create a file handler with JSON formatting
file_handler = logging.FileHandler("strands_agents_sdk.log")
file_handler.setFormatter(JsonFormatter())
# Add the handler to the strands logger
logging.getLogger("strands").addHandler(file_handler)
  1. Configure Early: Set up logging configuration before initializing the agent
  2. Appropriate Levels: Use INFO for normal operation and DEBUG for troubleshooting
  3. Structured Log Format: Use the structured log format shown in examples for better parsing
  4. Performance: Be mindful of logging overhead in production environments
  5. Integration: Integrate Strands Agents SDK logging with your application’s logging system