@kittgen/nestjs-fluent-logger
v1.0.1
Published
Key Value Logger with fluent API and support for Redaction
Downloads
21
Readme
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', '[email protected]', 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=████[email protected] 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','[email protected]', emailLocal) | ██@ab.c | | emailLocalHalf | redacts first half of local part of email | .addRedacted('to','[email protected]', emailLocalHalf) | █[email protected] | | emailDomain | redacts domain part of email | .addRedacted('to','[email protected]', emailDomain) | Ed@███ | | emailDomainHalf | redacts first half of domain part of email | .addRedacted('to','[email protected]', emailDomainHalf) | Ed@██.c |
Redaction strategies Composition
It is possible to compose redaction strategies, e.g.:
logger.fluent()
.add('email','[email protected]', emailLocalHalf, emailDomainHalf) // this redacts [email protected] 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.