nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
67.7k stars 7.63k forks source link

In Logger, the error stack goes to the next line. #7626

Closed CatsMiaow closed 3 years ago

CatsMiaow commented 3 years ago

I cloned typescript-starter and tested it.

import { Controller, Get, Logger } from '@nestjs/common';
import { AppService } from './app.service';

@Controller()
export class AppController {
  private readonly logger: Logger = new Logger(AppController.name);

  constructor(private readonly appService: AppService) {}

  @Get()
  getHello(): string {
    this.logger.error({ test: 'foo', foo: 'bar' });
    this.logger.error('Test1');
    this.logger.error('Test2', 'TestStack');

    // It happens on this line.
    this.logger.error('Test3', 'TestStack', 'TestContext');

    return this.appService.getHello();
  }
}

image

https://github.com/nestjs/nest/blob/bddecac3a73e628dfe2a0202ea3000f47f0cc69e/packages/common/services/console-logger.service.ts#L176 It seems to contain stack inside messages.

kamilmysliwiec commented 3 years ago

Your logger has the context already specified in this line:

private readonly logger: Logger = new Logger(AppController.name);

so this:

this.logger.error('Test3', 'TestStack', 'TestContext');

will be interpreted as [message, message, stack] instead.

This is the expected behavior.