Structured Logging
Write logs with a fluid API that makes adding tags, metadata and errors simple.
A layer on top of Javascript logging libraries to provide a consistent logging experience.
// Example using the Pino logging library with LogLayer
// You can also start out with a console logger and swap to another later!
import { LogLayer } from 'loglayer';
import { pino } from 'pino';
import { PinoTransport } from '@loglayer/transport-pino';
import { redactionPlugin } from '@loglayer/plugin-redaction';
const log = new LogLayer({
// Multiple loggers can also be used at the same time.
transport: new PinoTransport({
logger: pino()
}),
// Plugins modify log data before it's shipped to your logging library.
plugins: [
redactionPlugin({
paths: ['password'],
censor: '[REDACTED]',
}),
],
// Put context data in a specific field (default is flattened)
contextFieldName: 'context',
// Put metadata in a specific field (default is flattened)
metadataFieldName: 'metadata',
})
// persisted data that is always included in logs
log.withContext({
path: "/",
reqId: "1234"
})
log.withPrefix("[my-app]")
.withError(new Error('test'))
// data that is included for this log entry only
.withMetadata({ some: 'data', password: 'my-pass' })
// Non-object data only (numbers and strings only)
// this can be omitted to just log an object / error
// by using .errorOnly() / .metadataOnly() instead of withError() / withMetadata()
.info('my message')
{
"level": 30,
"time": 1735857465669,
"msg": "[my-app] my message",
"context": {
"path": "/",
"reqId": "1234",
},
"metadata": {
"password": "[REDACTED]",
"some": "data",
},
"err":{
"type": "Error",
"message": "test",
"stack": "Error: test\n ..."
}
}
Name | Package | Changelog | Description |
---|---|---|---|
AWS Lambda Powertools Logger | Changelog | Logging for AWS Lambdas | |
Bunyan | Changelog | JSON logging library for Node.js | |
Console | Built-in | N/A | Simple console-based logging for development |
Consola | Changelog | Elegant console logger for Node.js and browser | |
Electron-log | Changelog | Logging library for Electron applications | |
Log4js | Changelog | Port of Log4j framework to Node.js | |
loglevel | Changelog | Minimal lightweight logging for JavaScript | |
Pino | Changelog | Very low overhead Node.js logger | |
Roarr | Changelog | JSON logger for Node.js and browser | |
Signale | Changelog | Highly configurable CLI logger | |
tslog | Changelog | Powerful, fast and expressive logging for TypeScript and JavaScript | |
Tracer | Changelog | Tracer logging library for Node.js | |
Winston | Changelog | A logger for just about everything |
Name | Package | Changelog | Description |
---|---|---|---|
Axiom | Changelog | Send logs to Axiom cloud logging platform | |
Datadog | Changelog | Server-side logging for Datadog | |
Datadog Browser Logs | Changelog | Browser-side logging for Datadog | |
Dynatrace | Changelog | Server-side logging for Dynatrace | |
Google Cloud Logging | Changelog | Server-side logging for Google Cloud Platform | |
New Relic | Changelog | Server-side logging for New Relic | |
Sumo Logic | Changelog | Send logs to Sumo Logic via HTTP Source |
Name | Package | Changelog | Description |
---|---|---|---|
Log File Rotation | Changelog | Write logs to local files with rotation support | |
OpenTelemetry | Changelog | Send logs using the OpenTelemetry Logs SDK |
Name | Package | Changelog | Description |
---|---|---|---|
Filter | Changelog | Filter logs using string patterns, regular expressions, or JSON Queries | |
OpenTelemetry | Changelog | Add OpenTelemetry trace context to logs | |
Sprintf | Changelog | Printf-style string formatting support | |
Redaction | Changelog | Redact sensitive information from logs |