Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: export outOfContext and storage #1060

Closed
wants to merge 1 commit into from
Closed

fix: export outOfContext and storage #1060

wants to merge 1 commit into from

Conversation

CatsMiaow
Copy link

Export the relevant object so that can reuse nestjs-pino in non-http environments.
Need to reuse outOfContext to keep the options set in LoggerModule.forRoot(options).

import { outOfContext, storage as loggerStorage, Store as LoggerStore } from 'nestjs-pino';
import type { Logger as PinoLogger } from 'pino';

...

@On({ event: 'something' })
public async webSocketEvent(): Promise<void> {
  const store = new LoggerStore((<PinoLogger>outOfContext).child({
    foo: 'bar',
    user: 'test',
  }));

  await loggerStorage.run(store, async () => {
    // logic...
    this.logger.log('hello'); // {"foo":"bar","user":"test","msg":"hello" ... }
  });
}

This is not a solution to this issue(#803), but it can be used as a temporary measure.

@iamolegga
Copy link
Owner

I would prefer better developer experience instead of exporting internals. Now we will export it, after we should deprecate it and release new major version with better solution. Moreover there are no docs and tests for such usage.

Sorry, but I cannot merge it in the current state.

@iamolegga iamolegga closed this Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants