pinojs / pino-pretty

🌲Basic prettifier for Pino log lines

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

topninja opened this issue · comments

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

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

image

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

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.

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");

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