Structured Logging
Write logs with a fluid API that makes adding tags, metadata and errors simple.
LogLayer: The modern logging library for Typescript / Javascript
A layer on top of Javascript logging libraries to provide a consistent logging experience.

Write logs with a fluid API that makes adding tags, metadata and errors simple.
Use console logging when starting out, then switch to another logging provider later without changing your application code.
Transform, enrich, and filter logs with plugins that lets you customize every aspect of your logging pipeline.
Fan out logs to multiple logging libraries like Pino and cloud providers like DataDog at the same time.
A transport and plugin is available for connecting logs to OpenTelemetry.
A mixin is available to add methods to LogLayer to easily send metrics with your logs to StatsD.
A transport is available to send logs via HTTP.
Rotate log files based on time or size with optional batching and compression with the Log File Rotation transport.
javascript
// 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')json5
{
"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 ..."
}
}Use the Pretty Terminal Transport to view logs in the terminal with filtering and detailed viewing capabilities.
Extend LogLayer with StatsD metrics support using the Hot Shots Mixin:
typescript
import { LogLayer, useLogLayerMixin, ConsoleTransport } from 'loglayer';
import { StatsD } from 'hot-shots';
import { hotshotsMixin } from '@loglayer/mixin-hot-shots';
// Create a StatsD client
const statsd = new StatsD({
host: 'localhost',
port: 8125
});
// Register the mixin (must be called before creating LogLayer instances)
useLogLayerMixin(hotshotsMixin(statsd));
// Create LogLayer instance
const log = new LogLayer({
transport: new ConsoleTransport({
logger: console
})
});
// Use StatsD methods through the stats property
log.stats.increment('request.count').send();
log.info('Request received');
log.stats.timing('request.duration', 150).send();
log.info('Request processed');
log.stats.gauge('active.connections', 42).send();
log.info('Connection established');| Name | Description |
|---|---|
| Console Browser Server Deno Bun | Simple console-based logging for development |
| Structured Browser Server Deno Bun | Console-based structured logging with level, time, and msg fields enabled by default |
| Blank Transport Browser Server Deno Bun | For quickly creating / prototyping new transports |
| Name | Package | Changelog | Description |
|---|---|---|---|
| Bunyan Browser Server | Changelog | JSON logging library for Node.js | |
| Consola Server | Changelog | Elegant console logger for Node.js and browser | |
| Electron-log Server | Changelog | Logging library for Electron applications | |
| Log4js Server | Changelog | Port of Log4j framework to Node.js | |
| loglevel Browser Server | Changelog | Minimal lightweight logging for JavaScript | |
| LogTape Browser Server Deno Bun | Changelog | Modern, structured logging library for TypeScript and JavaScript | |
| Pino Browser Server | Changelog | Very low overhead Node.js logger | |
| Roarr Browser Server | Changelog | JSON logger for Node.js and browser | |
| Signale Server | Changelog | Highly configurable CLI logger | |
| tslog Browser Server Deno Bun | Changelog | Powerful, fast and expressive logging for TypeScript and JavaScript | |
| Tracer Server | Changelog | Tracer logging library for Node.js | |
| Winston Browser Server | Changelog | A logger for just about everything |
| Name | Package | Changelog | Description |
|---|---|---|---|
| Amazon CloudWatch Logs Server | Changelog | Logging for Amazon CloudWatch Logs | |
| AWS Lambda Powertools Logger Server | Changelog | Logging for AWS Lambdas | |
| Axiom Server | Changelog | Send logs to Axiom cloud logging platform | |
| Better Stack Server Deno Bun | Changelog | Send logs to Better Stack log management platform | |
| Datadog Server | Changelog | Server-side logging for Datadog | |
| Datadog Browser Logs Browser | Changelog | Browser-side logging for Datadog | |
| Dynatrace Server | Changelog | Server-side logging for Dynatrace | |
| Google Cloud Logging Server | Changelog | Server-side logging for Google Cloud Platform | |
| New Relic Server | Changelog | Server-side logging for New Relic | |
| Sentry Browser Server Deno Bun | Changelog | Send structured logs to Sentry using the Sentry SDK logger API | |
| Logflare Server Deno Bun | Changelog | Send logs to Logflare log ingestion and querying engine | |
| Sumo Logic Server | Changelog | Send logs to Sumo Logic via HTTP Source | |
| VictoriaLogs Server Deno Bun | Changelog | Send logs to VictoriaLogs by Victoria Metrics using JSON stream API |
| Name | Package | Changelog | Description |
|---|---|---|---|
| HTTP Browser Server Deno Bun | Changelog | Generic HTTP transport with batching, compression, and retry support | |
| Log File Rotation Server | Changelog | Write logs to local files with rotation support | |
| OpenTelemetry Server | Changelog | Send logs using the OpenTelemetry Logs SDK | |
| Pretty Terminal Server | Changelog | Pretty prints logs in the terminal with text search / advanced interactivity. | |
| Simple Pretty Terminal Browser Server Deno Bun | Changelog | Pretty prints logs in the browser / terminal / Next.js. |
| Name | Package | Changelog | Description |
|---|---|---|---|
| Datadog APM Trace Injector Server | Changelog | Automatically inject Datadog APM trace context into logs for correlation | |
| Filter Browser Server | Changelog | Filter logs using string patterns, regular expressions, or JSON Queries | |
| OpenTelemetry Server | Changelog | Add OpenTelemetry trace context to logs | |
| Redaction Browser Server | Changelog | Redact sensitive information from logs | |
| Sprintf Browser Server | Changelog | Printf-style string formatting support |
| Name | Package | Changelog | Description |
|---|---|---|---|
| ElysiaJS Server Bun Deno | Changelog | Request-scoped logging for ElysiaJS with auto request/response logging | |
| Express Server Bun Deno | Changelog | Request-scoped logging for Express with auto request/response logging | |
| Fastify Server | Changelog | Request-scoped logging for Fastify with auto request/response logging | |
| Hono Server Bun Deno | Changelog | Request-scoped logging for Hono with auto request/response logging | |
| Koa Server | Changelog | Request-scoped logging for Koa with auto request/response logging |
| Name | Package | Description |
|---|---|---|
| Datadog Metrics (HTTP) Server | Adds the datadog-metrics API to LogLayer | |
| Hot-Shots (StatsD) Server | Adds the hot-shots API to LogLayer |
LogLayer is made with ❤️ by Theo Gravity / Disaresta. Logo by Akshaya Madhavan.