Skip to content

LogLayer

Unifies Logging

A layer on top of Javascript logging libraries to provide a consistent logging experience.

LogLayer

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]',
    }),
  ],
})

log.withPrefix("[my-app]")
  .withMetadata({ some: 'data', password: 'my-pass' })
  .withError(new Error('test'))
  .info('my message')
json5
{
  "level": 30,
  "time": 1735857465669,
  "msg": "[my-app] my message",
  // The placement of these fields are also configurable!
  "password": "[REDACTED]",
  "some": "data",
  "err":{
    "type": "Error",
    "message": "test",
    "stack": "Error: test\n ..."
  }
}

Logging Libraries

  • AWS Lambda Powertools Logger - Logging for AWS Lambdas
  • Bunyan - JSON logging library for Node.js
  • Console - Simple console-based logging for development
  • Consola - Elegant console logger for Node.js and browser
  • Electron-log - Logging library for Electron applications
  • Log4js - Port of Log4j framework to Node.js
  • loglevel - Minimal lightweight logging for JavaScript
  • Pino - Very low overhead Node.js logger
  • Roarr - JSON logger for Node.js and browser
  • Signale - Highly configurable CLI logger
  • tslog - Powerful, fast and expressive logging for TypeScript and JavaScript
  • Tracer - Tracer logging library for Node.js
  • Winston - A logger for just about everything.

Cloud Providers