@kittgen/nestjs-fluent-logger
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Kittgen Nestjs Key Value FluentLogger

Key Value Logger with support for redaction

Check the main page for Kittgen for further information.

Usage

Installation

npm i @kittgen/nestjs-fluent-logger

Using Fluent Key Value API

Example usage of logger

Log Example

import { FluentLogger } from '@kittgen/nestjs-fluent-logger';

class EmailService {
  constructor() {
    const logger = new FluentLogger(EmailService.name)
  }
  // ...
  logger.fluent()
        .add('send', 'email')
        .add('success', true)
        .addRedacted('userId', '123123', half)
        .addRedacted('to', 'johndoe@example.com', emailLocalHalf)
        .add('templateName', 'my-email-template')
        .log()
  //...
}

logs

[Nest] 7554 - 01/17/2021, 9:10:31 PM   [EmailService] send=email success=true userId=███123 to=████doe@example.com templateName=my-email-template

Loglevels

FluentLogger supports same log levels as the Nest logger.

  logger.fluent()
        .add('success', true)
        .log() //.error() , .warn(), .debug(), .verbose()

Context

It accepts the same arguments as Nest, like e.g. Context. Just without the message part, which is generated through the key value pairs.

  logger.fluent()
        .add('success', true)
        .log(myContext)

Redaction Strategies

This package comes with a set of predefined redaction strategies. You can also provide you own.

Strategy Description Using Redacts to
fully (default) redacts every char with a Bar .addRedacted('to','Eddy') ████
half same as firstHalf .addRedacted('to','Eddy', half) ██dy
firstHalf redacts the first half with bars .addRedacted('to','Eddy', firstHalf) ██dy
lastHalf redacts the last half with bars .addRedacted('to','Eddy', lastHalf) Ed██
replaceWith redacts with specified replacement .addRedacted('to','Eddy', replaceWith('❤️')) ❤️
emailLocal redacts local part of email .addRedacted('to','Ed@ab.c', emailLocal) ██@ab.c
emailLocalHalf redacts first half of local part of email .addRedacted('to','Ed@ab.c', emailLocalHalf) d@ab.c
emailDomain redacts domain part of email .addRedacted('to','Ed@ab.c', emailDomain) Ed@███
emailDomainHalf redacts first half of domain part of email .addRedacted('to','Ed@ab.c', emailDomainHalf) Ed@██.c

Redaction strategies Composition

It is possible to compose redaction strategies, e.g.:

logger.fluent()
        .add('email','eddy@example.com', emailLocalHalf, emailDomainHalf) // this redacts  eddy@example.com to ██dy@██████le.com
        .log()

Usage as normal Nest Logger

FluentLogger is an extension of the default Nest Logger and supports all it's features.

import { FluentLogger } from '@kittgen/nestjs-fluent-logger';

const logger = new FluentLogger()
logger.log('hello world')

Local Development

Local Library Development

Important Commands

# start in watcher mode
npm start

# builds to the 'dist' folder
npm run build

# runs the tests
npm test

Commits

We use conventional commits for nice commit messages and automated versioning/changelog.

This packages uses TSDX.

License

Kittgen is licensed under MIT. See LICENSE.

Authors

Kittgen is developed by Otto von Wesendonk and Edgar Müller.

Package Sidebar

Install

npm i @kittgen/nestjs-fluent-logger

Weekly Downloads

5

Version

1.0.1

License

MIT

Unpacked Size

46.3 kB

Total Files

14

Last publish

Collaborators

  • edgar.m.mueller
  • ottovw