Logging
MindedJS provides a structured logging system that helps you monitor, debug, and audit your agent's behavior. The logger is available throughout your agent code and provides consistent, contextual logging with proper PII handling.
Using the Logger
Import the logger from MindedJS:
import { logger } from 'mindedjs';
The logger is also available in all tool contexts, so you can use it directly in your tools without importing.
Log Levels
The logger supports standard log levels:
// Info level - general information
logger.info('Processing customer request');
// Warning level - potential issues
logger.warn('Customer tier not found, using default');
// Error level - errors and exceptions
logger.error('Failed to process payment');
// Debug level - detailed debugging information
logger.debug('Memory state updated');
Structured Logging
Use structured logging with contextual data for better observability:
// Basic structured logging
logger.info('Order processed', {
orderId: 'ORD-123',
customerId: 'CUST-456',
amount: 99.99,
});
// Include session context in tools
logger.info('Tool execution started', {
sessionId: state.sessionId,
toolName: 'refundOrder',
orderId: input.orderId,
});
Log Configuration
The logger can be configured through environment variables:
# Set log level (debug, info, warn, error)
LOG_LEVEL=info
# In development, you might want debug level
LOG_LEVEL=debug
Best Practices
Always Include Session Context: Include
sessionId
in all tool-related logsUse Appropriate Log Levels: Don't use
info
for debugging informationStructure Your Data: Use objects for structured logging rather than strings
Log State Changes: Log important state transitions and memory updates
Error Context: Use
err
parameter for error objects to get proper stack tracesPerformance Metrics: Log timing information for performance monitoring
Last updated