LogLayer - Unify your Javascript logging

LogLayer - Unify your Javascript logging

Visit Site

LogLayer: Unifying JavaScript Logging Libraries

LogLayer is a unified layer on top of popular JavaScript logging libraries, providing a consistent logging experience across various environments. Its primary goal is to simplify the process of integrating multiple logging providers into a single application.

Key Features:

Structured Logging

LogLayer offers structured logging capabilities through its fluid API. This allows developers to easily add tags, metadata, and errors to their logs with minimal code changes.

Bring Your Own Logger (BYOL)

The LogLayer plugin system enables users to switch between different logging providers without modifying their application code. Developers can start with console logging and then transition to another provider later on.

Extensible Plugin System

LogLayer's plugin system allows developers to customize every aspect of the logging pipeline, from log transformation and enrichment to filtering and aggregation.

Multi-logger Support

LogLayer supports fan-out to multiple logging libraries and cloud providers simultaneously. This means that applications can seamlessly integrate with various logging solutions, such as DataDog and New Relic.

Supported Logging Libraries and Cloud Providers:

LogLayer integrates with a wide range of popular logging libraries and cloud providers, including:

  • Logging Libraries:
    • AWS Lambda Powertools Logger
    • Bunyan
    • Console
    • Consola
    • Electron-log
    • Log4js
    • Pino
    • Roarr
    • Signale
    • tslog
    • Tracer
    • Winston
  • Cloud Providers:
    • Datadog (Server-side and Browser-side)
    • New Relic

Example Usage:

import { LogLayer } from 'loglayer';
import { pino } from 'pino';
import { PinoTransport } from '@loglayer/transport-pino';
import { redactionPlugin } from '@loglayer/plugin-redaction';

const log = new LogLayer({
    transport: new PinoTransport({
        logger: pino()
    }),
    plugins: [
        redactionPlugin({
            paths: ['password'],
            censor: '[REDACTED]',
        })
    ]
});

log.withPrefix("[my-app]")
    .withMetadata({ some: 'data', password: 'my-pass' })
    .withError(new Error('test'))
    .info('my message');

This code snippet demonstrates how to create a LogLayer instance with a Pino transport and apply a redaction plugin to the logs. The resulting log entry would look like this:

{
  "level": 30,
  "time": 1735857465669,
  "msg": "[my-app] my message",
  "password": "[REDACTED]",
  "some": "data",
  "err":{
    "type": "Error",
    "message": "test",
    "stack": "Error: test\n ..."
  }
}

By using LogLayer, developers can simplify the process of integrating multiple logging providers into their applications and ensure a consistent logging experience across different environments.