@agentlib/logger
Structured logging middleware for AgentLIB — plug-and-play observability for agent runs.Installation
Overview
The@agentlib/logger package provides a middleware that logs agent lifecycle events with:
- Structured log output
- Configurable log levels
- Timing measurements
- Scope filtering
- Custom transports
- Zero-config defaults
Quick Start
Configuration
Usage Examples
Default Configuration
run:beforeandrun:afterat INFO levelstep:*andtool:*at DEBUG level- Includes timing measurements
Debug Mode
- Step start/end
- Tool invocations
- Detailed timing
Scope Filtering
Disable Timing
Custom Prefix
Log Levels
Level Hierarchy
level: 'info' will show INFO, WARN, and ERROR logs.
Auto-Level Mapping
Scopes are automatically mapped to log levels:run:before,run:after→ INFOstep:before,step:after→ DEBUGtool:before,tool:after→ DEBUG
Custom Transports
JSON Transport
File Transport
Winston Integration
Pino Integration
Log Entry Structure
Middleware Scopes
Available scopes:run:before- Before agent run startsrun:after- After agent run completesstep:before- Before reasoning stepstep:after- After reasoning steptool:before- Before tool executiontool:after- After tool execution
Timing Measurements
Whentiming: true (default), the logger measures duration between :before and :after scopes:
Advanced Usage
Conditional Logging
Multi-Transport
Metric Collection
Selective Scope Logging
Best Practices
-
Use INFO for production:
-
Use DEBUG for development:
-
Filter noisy scopes:
-
Structured logging to files:
-
Combine with monitoring tools:
Requirements
- Node.js: >= 18.0.0
- Dependencies:
@agentlib/core(workspace)
Exports
Functions
createLogger(config?)- Create logging middleware
Types
LoggerMiddlewareConfig- Configuration interfaceLogLevel- Log level typeLogEntry- Log entry structureLogTransport- Transport function type
Related Packages
- @agentlib/core - Core middleware system