pinojs / pino-pretty

🌲Basic prettifier for Pino log lines
MIT License
1.27k stars 150 forks source link

Where's my error occur in my project? (How to find exact code line and its file name) #368

Closed topninja closed 2 years ago

topninja commented 2 years ago

Hello team. I added logger in many places of my project And sometimes logger has error logs.

const pino = require('pino');
const path = require('path');
const logger = pino({
    prettyPrint: {
        messageFormat: '{filename}: {msg}',
        ignore: 'pid,hostname,filename',
    }
}).child({ filename: __dirname + '\\' + path.basename(__filename) });

I did like this so I can see which file, and its error message image But I want to know which line produce this error so I can find issue easily. How to do this?

Thanks

p.s. logger.error(new Error('payload is not valid')) by this, I can get line but shows few more.. I want only 1 line

mcollina commented 2 years ago

Remove messageFormat and you'll see a full stack trace.

topninja commented 2 years ago

image

I tried to do by removing messageFormat but shows only 1 line like above image.

mcollina commented 2 years ago

Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.

topninja commented 2 years ago

I added reproduction example already.

const pino = require('pino');
const path = require('path');
const logger = pino({
    prettyPrint: {
        messageFormat: '{filename}: {msg}',
        ignore: 'pid,hostname,filename',
    }
}).child({ filename: __dirname + '\\' + path.basename(__filename) });

logger.error("payload is not valid");
mcollina commented 2 years ago

You are not creating an error, so there is no stacktrace. If you want to get a stacktrace, create an error.