Plugins
Plugins extend logger functionality by transforming or filtering logs before they reach transports.
Overview
Plugins hook into the logging pipeline to:
- Filter logs based on level, namespace, or custom criteria
- Transform log data by adding, removing, or modifying fields
- Redact sensitive information like passwords or API keys
- Add context from global state or async local storage
typescript
const logger = createLogger({
namespace: 'my-app',
plugins: [
createFilterPlugin({ minLevel: 'info' }),
createRedactPlugin({ paths: ['password'] }),
createGlobalLogContextPlugin()
]
});Plugin Pipeline
Plugins execute in two phases:
Log Call
↓
plugins shouldLog (filtering)
↓
plugins transformLogContext (transformation)
↓
TransportsIf any shouldLog plugin returns false, the log is dropped and never reaches transports.
Built-in Plugins
Crowlog provides four built-in plugins:
- Filter Plugin - Filter logs by level, namespace, or custom logic
- Redact Plugin - Automatically redact sensitive fields
- Global Log Context Plugin - Add application-wide context
- Async Context Plugin - Add async request-scoped context
Order Matters
Plugins execute in the order they're defined:
typescript
createLogger({
namespace: 'my-app',
plugins: [
createFilterPlugin({ minLevel: 'info' }), // Runs first
createRedactPlugin({ paths: ['password'] }) // Runs second
]
});Next Steps
- Child Loggers - Create child loggers with inherited configuration
- Testing - Test your logging with in-memory transport
- Custom Plugins - Create your own plugins