Logger¶
Structured logging with automatic session context inclusion for tools and orchestrators.
Logger Class¶
::: agenticai_core.runtime.sessions.request_context.Logger options: show_root_heading: true show_source: false members_order: source
Basic Usage¶
from agenticai_core.runtime.sessions.request_context import Logger
@Tool.register(name="my_tool", description="Tool with logging")
async def my_tool(operation: str):
logger = Logger('MyTool')
await logger.info(f"Starting operation: {operation}")
try:
# Your tool logic here
result = {"success": True, "data": "processed"}
await logger.info("Operation completed successfully")
return result
except Exception as e:
await logger.error(f"Operation failed: {str(e)}")
raise
With RequestContext¶
from agenticai_core.runtime.sessions.request_context import RequestContext, Logger
@Tool.register(name="integrated_tool", description="Tool with shared context")
async def integrated_tool():
# Create shared context
ctx = RequestContext()
logger = Logger('IntegratedTool', request_context=ctx)
# Access environment and memory through same context
env = await ctx.get_environment_variables()
memory = ctx.get_memory()
await logger.info("Tool execution completed")
return {"success": True}
Log Levels¶
logger = Logger('MyTool')
await logger.debug("Detailed diagnostic information")
await logger.info("General operational information")
await logger.warning("Potential issue requiring attention")
await logger.error("Error affecting functionality")
Best Practices¶
- Use descriptive logger names:
Logger('UserAuthTool')instead ofLogger('Tool') - Include context:
f"Processing payment: amount=${amount}, user={user_id}" - Don't log sensitive data: Sanitize or redact passwords, API keys, tokens
- Use appropriate levels: Debug for diagnostics, info for operations, warning/error for issues
Troubleshooting¶
Common Issues¶
-
Logger Not Capturing Session Context:
-
Missing Log Output:
-
Performance Issues with Logging:
Related resources
- RequestContext API - Session context and environment variables
- Tracer API - Distributed tracing and monitoring
- Working with Tools Guide - Tool development patterns
- Runtime Overview - Complete runtime API reference