nest-trace-logging
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Nest.js Traceability enhanced Logging Module

This Nest.js (https://nestjs.com/) Module provides a Logger built on top of Winston (https://www.npmjs.com/package/winston) which is enhances with a unique Request ID when called in a HTTP context.

Installation

npm install nest-trace-logging

Example

Initialize module:

import { Module} from "@nestjs/common"
import { LoggingModule } from "nest-trace-logging";

@Module({
    imports: [LoggingModule],
})
class ExampleModule {}

Usage of provider logger (HTTP context):

import { Controller } from "@nestjs/common"
import { Logger } from "nest-trace-logging"

@Controller("foo")
class ExampleController {
    
    @Get("bar")
    someMethod() {
        Logger.debug("Some debug info ...")
    }
}

Result:

...
[debug] [2020-02-20T18:00:00.000Z] (RequestId=fe0dfdb4-3bca-41b7-8cfd-56d659579dea) Some debug info ...
...

Usage of provider logger (no HTTP context):

import { Logger } from "nest-trace-logging"

class ExampleService {   
    someMethod() {
        Logger.debug("Some other debug info ...")
    }
}

Result:

...
[debug] [2020-02-20T18:00:00.000Z] Some other debug info ...
...

Package Sidebar

Install

npm i nest-trace-logging

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

95.5 kB

Total Files

16

Last publish

Collaborators

  • jalorenz