Package Exports
- loglayer
Readme
loglayer
loglayer
is a unified logger that routes logs to various logging libraries and cloud providers while providing a fluent API for specifying log messages, metadata and errors.
- For full documentation, read the docs.
- Older 4.x documentation
// Example using the Pino logging library with LogLayer
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.
// Need to also ship to a cloud provider like DataDog at the same time? You can!
transport: new PinoTransport({
logger: pino()
}),
// Plugins can be created to 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')
{
"level":30,
"time":1735857465669,
"pid":30863,
"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 ..."
}
}
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')