Logging
Logger Configuration
The LeanMCP logger provides structured logging with multiple levels:packages/core/src/logger.ts:60
Log Levels
packages/core/src/logger.ts:5
Default Logger
Use the pre-configured default logger:packages/core/src/logger.ts:149
Log Formatting
Logs are automatically formatted with:- Timestamp: ISO 8601 format
- Prefix: Custom prefix (e.g.,
[MyService]) - Context: Module or component name
- Level: Log level label
- Colors: ANSI color codes (can be disabled)
packages/core/src/logger.ts:78
Custom Log Handlers
Integrate with third-party services (PostHog, Sentry, Datadog, etc.):packages/core/src/logger.ts:42
Log Payload Structure
packages/core/src/logger.ts:32
Session Monitoring
Session Lifecycle Logging
Monitor session creation, restoration, and deletion:packages/core/src/session-provider.ts:53
Track Active Sessions
Monitor the number of active sessions:packages/core/src/session-provider.ts:180
Authentication Debugging
Token Verification Errors
Detailed error messages for authentication failures:packages/auth/src/decorators.ts:52
Auth Provider Logging
Log authentication events:Elicitation Debugging
Log Elicitation Requests
Debug form elicitation flows:packages/elicitation/src/types.ts:116
Environment Variable Debugging
Log Available Variables
Check which environment variables are available:packages/env-injection/src/env-context.ts:60
Production Monitoring
Health Checks
Implement health check endpoints:Metrics Collection
Collect custom metrics:Error Tracking
Integrate with Sentry or similar:Performance Monitoring
Request Timing
Log request duration:Session Operations
Monitor session operation performance:Best Practices
1. Use Appropriate Log Levels
2. Structured Logging
Use objects for structured data:3. Disable Colors in Production
4. Use Context for Module Identification
5. Handle Logger Errors Gracefully
The logger catches handler errors to prevent logging from breaking your app:packages/core/src/logger.ts:114
Next Steps
Deployment
Deploy to production
Authentication
Secure your MCP server