6.3.1 • Published 3 months ago

loglayer v6.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

loglayer

NPM version NPM Downloads TypeScript

loglayer is a unified logger that routes logs to various logging libraries, cloud providers, files, and OpenTelemetry while providing a fluent API for specifying log messages, metadata and errors.

// 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, booleans, 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 ..."
  }
}

With the Pretty Terminal Transport:

Pretty Terminal Transport

Installation

Install the core package:

npm i loglayer

Quick Start

import { LogLayer, ConsoleTransport } from 'loglayer'

const log = new LogLayer({
  transport: new ConsoleTransport({
    logger: console,
  }),
})

log
  .withMetadata({ some: 'data'})
  .withError(new Error('test'))
  .info('my message')
5.5.1

5 months ago

5.5.0

5 months ago

5.1.4

5 months ago

5.1.3

5 months ago

5.3.0

5 months ago

5.1.2

5 months ago

5.1.1

5 months ago

5.1.0

5 months ago

6.1.0

4 months ago

6.3.0

3 months ago

6.1.2

4 months ago

6.1.1

4 months ago

6.3.1

3 months ago

6.1.3

4 months ago

5.0.9

5 months ago

5.0.8

5 months ago

5.0.7

5 months ago

5.6.0

4 months ago

5.0.6

5 months ago

5.4.1

5 months ago

5.0.5

5 months ago

5.4.0

5 months ago

5.0.4

5 months ago

5.0.3

5 months ago

5.2.0

5 months ago

5.0.2

5 months ago

5.0.1

5 months ago

5.0.10

5 months ago

5.0.0

5 months ago

5.0.11

5 months ago

5.0.12

5 months ago

6.0.0

4 months ago

6.2.0

3 months ago

5.7.0

4 months ago

4.8.0

9 months ago

4.5.0

9 months ago

4.4.1

9 months ago

4.7.0

9 months ago

4.6.1

9 months ago

4.6.0

9 months ago

4.4.0

1 year ago

4.3.3

1 year ago

4.3.2

1 year ago

4.3.1

1 year ago

4.3.0

1 year ago

4.1.0

1 year ago

4.0.0

1 year ago

4.2.1

1 year ago

4.2.0

1 year ago

4.1.1

1 year ago

3.1.0

1 year ago

3.0.1

1 year ago

3.0.0

1 year ago

2.1.0

2 years ago

2.0.3

2 years ago

1.6.0

2 years ago

1.5.0

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.3.4

3 years ago

1.1.1

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.2.1

3 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago