-
Notifications
You must be signed in to change notification settings - Fork 109
Open
Labels
enhancementNew feature or requestNew feature or request
Description
- I've read the docs of nestjs-pino
- I've read the docs of pino
- I couldn't find the same question about nestjs-pino
Question
I'm trying to use logger.assign outside of HTTP context. Specifically, inside sqs consumer's handleMessage function.
I figured out with the help of #788 to initiate the storage.run on my own. The problem was that i don't have access to req.log so i used PinoLogger.root instead. Is this supposed to be used like this?
import { storage, Store } from 'nestjs-pino/storage';
import { PinoLogger } from 'nestjs-pino';
---
this.consumer = Consumer.create({
// this magic creates AsyncLocalStorage context
// for nestjs-pino to work with. It allows the use
// of this.logger.assign() method.
handleMessage: message =>
storage.run(new Store(PinoLogger.root), () =>
this.processMessage(message),
),
});It seems to work fine. But want to make sure we won't break something in strange ways.
I guess this also relates to @nestjs/bull and @nestjs/microservices are those environments supported? As they are similarly not inside HTTP context (not passing middlewares afaik).
Edit: If this is a valid usage, maybe it could be wrapped in a nicer withNestPinoContext(() => this.processMessage(message)) like function.
mathieubergeron, Francismb, albertorestifo, notmd, micalevisk and 32 more
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request