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

Support for @algoan/nestjs-logging-interceptor? #268

Closed
GrabbenD opened this issue Nov 19, 2020 · 1 comment
Closed

Support for @algoan/nestjs-logging-interceptor? #268

GrabbenD opened this issue Nov 19, 2020 · 1 comment

Comments

@GrabbenD
Copy link

Hey there!

As it turns out none of the messages from @algoan/nestjs-logging-interceptor (source | npm) are being captured when using nest-winston. That's not the case if I switch to nestjs-pino. I also noticed that nestjs-pino claims that it supports Autobind request data to logs, is that maybe why?

Any help is highly appreciated!

@gremo
Copy link
Owner

gremo commented Dec 30, 2020

Hi, nest-winston works out of the box with @algoan/nestjs-logging-interceptor without any special configuration. Just setup the library as explained in the section "Use as the main Nest logger". I've done a quick test for you and it works fine.

There is nothing special with nestjs-pino or nest-winston, both work with the interceptor if you replace the Nest logger with a custom logger. I still think that intercepting requests is something out of the scope of this library. You can easily use @algoan/nestjs-logging-interceptor or any library that provides that interceptor.

Here is a minimal example (src/app.module.ts):

import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { LoggingInterceptor } from '@algoan/nestjs-logging-interceptor';
import {
  utilities as nestWinstonModuleUtilities,
  WinstonModule,
} from 'nest-winston';
import * as winston from 'winston';

@Module({
  imports: [
    WinstonModule.forRoot({
      transports: [
        new winston.transports.Console({
          format: winston.format.combine(
            winston.format.timestamp(),
            nestWinstonModuleUtilities.format.nestLike(),
          ),
        }),
      ],
    }),
  ],
  controllers: [AppController],
  providers: [
    AppService,
    {
      provide: APP_INTERCEPTOR,
      useClass: LoggingInterceptor,
    },
  ],
})
export class AppModule {}

The key part is to use it as Nest logger (src/main.ts):

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.useLogger(app.get(WINSTON_MODULE_NEST_PROVIDER));
  await app.listen(3000);
}
bootstrap();

Logging

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

No branches or pull requests

2 participants