pinojs / pino

🌲 super fast, all natural json logger
http://getpino.io
MIT License
14.16k stars 876 forks source link

Pino browser filename and line reporting #687

Open travikk opened 5 years ago

travikk commented 5 years ago

Hey,

Using standard config for pino:

const logLevel = 'debug'
const loggerOptions: loggerFactory.LoggerOptions = {
   name: 'rootLogger',
   level: logLevel,
}

const rootLogger = loggerFactory(loggerOptions)

export const getLogger = (name: string): Logger => {
   return rootLogger.child({name})
}

when I try to log anything, chrome console doesn't show the correct file:line from where the log initiates, but rather shows browser.js:174 (which basically corresponds to pino internals).

Ideally, this is fixed and when I put a log statement anywhere in the code, the actual filename and line is reported.

jsumners commented 5 years ago

Pino does not log the line at which the log method was invoked. https://github.com/pinojs/pino-caller adds such functionality in Node, but I don't know about the browser.

travikk commented 5 years ago

@jsumners so console does this automatically, when you invoke any of the loggers (i.e. console.debug); but because those are invoked from browser.js, it's that file that gets reported to the browser's console.

Here's a possible solution:

https://stackoverflow.com/questions/13815640/a-proper-wrapper-for-console-log-with-correct-line-number

jsumners commented 5 years ago

PRs are welcome.