Update Tutorial

p-sw 2025-03-26 23:09:36 +00:00
parent 4848425075
commit 9539d633ca

@ -1,5 +1,21 @@
In this page, we'll provide a guide to learn how to use NestLogged package.
# Setup
Since `v3.3.0`, you should put `ConsoleLogger` exported from nestlogged package to the `NestFactory.create` call.
```ts
import { ConsoleLogger } from 'nestlogged';
const app = await NestFactory.create(AppModule, {
logger: new ConsoleLogger(),
});
```
The definition of ConsoleLogger is 100% same with ConsoleLogger from `@nestjs/common`, so you can just use it normally.
This new ConsoleLogger handles additional request scope parameter internally.
# Method Logging
## Basic
@ -86,4 +102,13 @@ export function LoggedRoute<F extends Array<any>, R>(
options?: Partial<OverrideBuildOptions>
) {
...
}
}
```
## Logger Initialization
For LoggedFunction and LoggedRoute decorator, it will initialize new `ScopedLogger` if it does not exists as `logger` property in the class. This initialization is processed on the first call of decorated function.
`ScopedLogger` is the new class extending `Logger` from `@nestjs/common`, adding ability to add scope and scope id to each logs. But you don't have to worry about it, it's not a whole new system. It's completely same as usual logging, and internal code will do all the "scope" processes.
If you want to know more about scoped logging, check Logger Injection & Scoped Logging.