Updated Tutorial (markdown)
parent
be93994a66
commit
be56a30fc8
16
Tutorial.md
16
Tutorial.md
@ -78,7 +78,7 @@ export class AppController {
|
||||
}
|
||||
```
|
||||
|
||||
It will automatically add logs to your route, and log it when the route method is called.
|
||||
It will automatically add logs to your route, and print it when the route method is called.
|
||||
|
||||
```md
|
||||
[Nest] 2378244 - 12/10/2023, 6:53:49 PM LOG [AppController] HIT HTTP AppController::/[GET] (getHello)
|
||||
@ -89,7 +89,7 @@ Note that it uses Logger class provided by `@nestjs/common` package.
|
||||
|
||||
### Changing the logging path
|
||||
|
||||
Basically LoggedRoute decorator automatically detect its path and method, and add to log.
|
||||
Basically LoggedRoute decorator automatically detect its path and http method, and build log with that.
|
||||
|
||||
But if you want, You can also provide its path to LoggedRoute decorator.
|
||||
|
||||
@ -152,18 +152,16 @@ export class AppService {
|
||||
}
|
||||
```
|
||||
|
||||
Unlike `LoggedRoute`, it can be placed without any rule, if you want.
|
||||
|
||||
The `LoggedFunction` decorator will automatically add logs to the call time.
|
||||
|
||||
When the `getHello` function called, it will automatically logs:
|
||||
When the `getHello` function called, it will automatically prints:
|
||||
|
||||
```md
|
||||
[Nest] 2459083 - 12/10/2023, 7:08:11 PM LOG [AppService] CALL getHello
|
||||
[Nest] 2459083 - 12/10/2023, 7:08:11 PM LOG [AppService] RETURNED getHello
|
||||
```
|
||||
|
||||
Since it is called from the http route `getHello`, the full log will printed.
|
||||
Since it is called from the http route `getHello`, the full log will printed like below.
|
||||
|
||||
```md
|
||||
[Nest] 2459083 - 12/10/2023, 7:08:11 PM LOG [AppController] HIT HTTP AppController::helloWorld[GET] (getHello)
|
||||
@ -172,13 +170,13 @@ Since it is called from the http route `getHello`, the full log will printed.
|
||||
[Nest] 2459083 - 12/10/2023, 7:08:11 PM LOG [AppController] RETURNED RESPONSE AppController::helloWorld[GET] (getHello)
|
||||
```
|
||||
|
||||
In this log, you can see that the `getHello` in `AppController` is calling the `getHello` function in AppService, and then return, and return.
|
||||
In this log, you can see that the `getHello` in `AppController` is calling the `getHello` function in `AppService`, and then return, and return.
|
||||
|
||||
You can easily see the flow of the http request. Pretty cool, isn't it?
|
||||
|
||||
## Parameter Logging
|
||||
|
||||
You can also add a parameter log when the function or route is called.
|
||||
You can also add a parameter log when the function or route method is called.
|
||||
|
||||
Let's modify the previous app and add some parameter, so we can get some arguments.
|
||||
|
||||
@ -219,7 +217,7 @@ export class AppService {
|
||||
|
||||
It's not that much different.
|
||||
|
||||
We add a query parameter `name`, pass to AppService's getHello, return Hello [name].
|
||||
We add a query parameter `name`, pass to `AppService`'s `getHello`, return `Hello [name]`.
|
||||
|
||||
Now, if we add a query `?name=NestLogged` to url, you can get "Hello NestLogged!" instead of "Hello World!".
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user