Migration from Pino
This guide helps you migrate from Pino to Vestig. Both are structured JSON loggers, so the concepts are similar.
Quick Comparison
| Feature | Pino | Vestig |
|---|---|---|
| Creation | pino() |
createLogger() |
| Child loggers | logger.child({ key }) |
logger.child('namespace', { context }) |
| Log levels | Same 5 levels | Same 5 levels |
| Transports | Separate process (pino-transport) | In-process, built-in |
| Structured | JSON by default | JSON in production |
| Sanitization | Custom serializers | Built-in sanitizer with presets |
| Context | Bindings | Async context + static context |
| Tracing | External (OpenTelemetry) | Built-in spans |
Basic Migration
Logger Creation
typescript
Logging
typescript
Child Loggers
typescript
Transport Migration
Console Transport
typescript
File Transport
typescript
HTTP Transport
typescript
Multiple Transports
typescript
Serializers → Sanitization
Custom Serializers (Pino)
typescript
Sanitization (Vestig)
typescript
Request Context
Async Hooks (Pino)
typescript
Async Context (Vestig)
typescript
Next.js Context
typescript
Log Levels
Both use the same levels with the same priority:
| Level | Pino Value | Vestig | Description |
|---|---|---|---|
| trace | 10 | trace |
Very detailed |
| debug | 20 | debug |
Debug info |
| info | 30 | info |
General info |
| warn | 40 | warn |
Warnings |
| error | 50 | error |
Errors |
| fatal | 60 | - | Use error with metadata |
Fatal Logs
typescript
Error Handling
Error Serialization
typescript
Error Cause Chains
typescript
Redaction
Redaction Paths (Pino)
typescript
Field Sanitization (Vestig)
typescript
Performance Comparison
Both libraries are designed for high performance:
| Aspect | Pino | Vestig |
|---|---|---|
| Log call overhead | ~5μs | ~10-20μs |
| Transport model | Separate process | In-process batching |
| Memory | Minimal | Bounded buffers |
| Async | Worker threads | AsyncLocalStorage |
Pino is slightly faster per-log, but Vestig provides more built-in features without external dependencies.
Common Patterns
Express Middleware
typescript
Database Logging
typescript
Migration Checklist
-
Install Vestig
bash -
Replace imports
typescript -
Update logger creation
- Replace
pino()withcreateLogger() - Convert
leveloption (same values) - Remove
transportoption, useaddTransport()instead
- Replace
-
Update child loggers
- Replace
logger.child({ key: value })withlogger.child('namespace', { context: { key: value } })
- Replace
-
Update serializers to sanitization
- Replace custom serializers with
sanitizeoption - Use presets for common cases
- Replace custom serializers with
-
Update async context
- Replace custom AsyncLocalStorage with
withContext() - Use
@vestig/nextfor Next.js
- Replace custom AsyncLocalStorage with
-
Update transports
- Remove pino-transport dependencies
- Use built-in Vestig transports
-
Test and verify
- Check log output format
- Verify error serialization
- Test async context propagation