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

error stack trace is not printed #73

Closed
TrejGun opened this issue Nov 30, 2019 · 5 comments
Closed

error stack trace is not printed #73

TrejGun opened this issue Nov 30, 2019 · 5 comments

Comments

@TrejGun
Copy link
Contributor

TrejGun commented Nov 30, 2019

Hi there! I'm not sure if this is feature request of bug repport.

what I do is configure winson in bootstrap function

  app.useLogger(app.get(WINSTON_MODULE_NEST_PROVIDER));

and app module

    WinstonModule.forRootAsync({
      useFactory: () => ({
        transports: [
          new transports.Console({
            format: format.combine(
              format.timestamp(),
              utilities.format.nestLike(),
            ),
          }),
        ],
      }),
    }),

and then use

  constructor(@Inject("winston") private readonly logger: Logger) {}

  public method(): void {
    const error = new Error("On no!");
    this.logger.error(error.message, error.stack, this.constructor.name);
  }

which print just

[NestWinston] Error     11/30/2019, 9:47:02 PM On no! - {}

according to docs it should print [context] and trace property in the meta data

ok lets do this ather way around

  constructor(@Inject("winston") private readonly logger: Logger) {}

  public method(): void {
    const error = new Error("On no!");
    this.logger.error(error);
  }

prints

[NestWinston] Error     11/30/2019, 9:51:27 PM undefined - {}

which is even worth

I was managed to make it work somehow

    WinstonModule.forRootAsync({
      useFactory: () => ({
        format: format.combine(
          format.errors({stack: true}), 
          format.timestamp()
        ),
        transports: [
          new transports.Console({
            format: format.printf(({level, context, timestamp, message, stack, trace}) => {
              let color, text;
              if (level === "error") {
                color = red;
                const lines = (stack || trace).split("\n");
                lines[0] = color(lines[0]);
                text = lines.join("\n");
              } else {
                color = green;
                text = color(message);
              }
              return `${color(`[Nest] ${process.pid}   -`)} ${new Date(timestamp).toLocaleString()}   ${context ? yellow("[" + context + "]") : ""} ${text}`;
            }),
          }),
        ],
      }),
    }),

now it prints Error object

[Nest] 20905   - 11/30/2019, 9:53:37 PM    Error: On no!
    at AuthController.biometric (~/path/to/file.ts:59:19)
    at ~/node_modules/@nestjs/core/router/router-execution-context.js:37:29
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at ~/node_modules/@nestjs/core/router/router-execution-context.js:45:28
    at ~/node_modules/@nestjs/core/router/router-proxy.js:8:17

but i still want to pass context and signature with 3 params just does not work. Please gimme some directions

@TrejGun TrejGun changed the title error stack is not printed error stack trace is not printed Dec 1, 2019
@gremo
Copy link
Owner

gremo commented Dec 3, 2019

@Piranit can you help me with this?

@TrejGun
Copy link
Contributor Author

TrejGun commented Dec 3, 2019

i can, what kind of help do you need?

@gremo
Copy link
Owner

gremo commented Dec 3, 2019

@TrejGun I don't know how error loggin works, so I was asking to him how stack trace is printed: is this a bug or something to be implemented?

@TrejGun
Copy link
Contributor Author

TrejGun commented Dec 3, 2019

it is impleneted and used for example in here
https://github.com/nestjs/nest/blob/master/packages/core/exceptions/base-exception-filter.ts#L55

and also implemented in your code
https://github.com/gremo/nest-winston/blob/master/src/winston.providers.ts#L13

but for some reason does not work, probably arguments are messed up when passed from nest to winston

@TrejGun
Copy link
Contributor Author

TrejGun commented Dec 3, 2019

ok I know what is wrong.

I have to inject WINSTON_MODULE_NEST_PROVIDER instead of WINSTON_MODULE_PROVIDER

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