1.0.1 • Published 3 years ago

@kittgen/nestjs-fluent-logger v1.0.1

Weekly downloads
31
License
MIT
Repository
github
Last release
3 years ago

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.

StrategyDescriptionUsingRedacts to
fully (default)redacts every char with a Bar.addRedacted('to','Eddy')████
halfsame as firstHalf.addRedacted('to','Eddy', half)██dy
firstHalfredacts the first half with bars.addRedacted('to','Eddy', firstHalf)██dy
lastHalfredacts the last half with bars.addRedacted('to','Eddy', lastHalf)Ed██
replaceWithredacts with specified replacement.addRedacted('to','Eddy', replaceWith('❤️'))❤️
emailLocalredacts local part of email.addRedacted('to','Ed@ab.c', emailLocal)██@ab.c
emailLocalHalfredacts first half of local part of email.addRedacted('to','Ed@ab.c', emailLocalHalf)█d@ab.c
emailDomainredacts domain part of email.addRedacted('to','Ed@ab.c', emailDomain)Ed@███
emailDomainHalfredacts 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.