Key Value Logger with support for redaction
Check the main page for Kittgen for further information.
npm i @kittgen/nestjs-fluent-logger
Example usage of logger
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
FluentLogger supports same log levels as the Nest logger.
logger.fluent()
.add('success', true)
.log() //.error() , .warn(), .debug(), .verbose()
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)
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 |
It is possible to compose redaction strategies, e.g.:
logger.fluent()
.add('email','[email protected]', emailLocalHalf, emailDomainHalf) // this redacts eddy@example.com to ██dy@██████le.com
.log()
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')
# start in watcher mode
npm start
# builds to the 'dist' folder
npm run build
# runs the tests
npm test
We use conventional commits for nice commit messages and automated versioning/changelog.
This packages uses TSDX.
Kittgen is licensed under MIT. See LICENSE.
Kittgen is developed by Otto von Wesendonk and Edgar Müller.