pino icon indicating copy to clipboard operation
pino copied to clipboard

Can not get mixin to work, am I doing it wrong? Is it broken?

Open kevinbcarney opened this issue 5 years ago • 7 comments

My code is below. const Pino = require('pino') ({ browser: { write: (o) => { loggerFunction(o) } }, level: "trace", // mixin is NOT working!!! mixin () { return { test: "42" } } })

kevinbcarney avatar Jan 30 '20 01:01 kevinbcarney

It's not currently supported by the browser API. Would you like to send a PR?

mcollina avatar Jan 30 '20 07:01 mcollina

I'm not sure what you mean by PR, but now that I know it isn't supported in the browser, I know how to proceed. I have a loggerFunction() function that sends the actual message to the logging server, so inside that function I'll add code to extend (if that's the right word) the msg string variable I pass in, to include the labels and values in object whose labels and values I wish to include.

kevinbcarney avatar Jan 30 '20 11:01 kevinbcarney

Simply put: https://github.com/pinojs/pino/blob/master/browser.js does not have this functionality. Only the server-side version of pino implements it. Would you like to contribute this by sending a Pull Reques?

mcollina avatar Jan 30 '20 16:01 mcollina

I very much appreciate the idea, but I'm a total newbie to Javascript. having started learning about two months ago. I feel like the casual weekend hiker who was just asked to give Everett a shot. Definitely not now. I have a lot of learning to do first.

kevinbcarney avatar Jan 30 '20 19:01 kevinbcarney

Hey I may be interested in implementing this. Having looked at the code my understanding is that I will have to attach a mixin property here: https://github.com/pinojs/pino/blob/master/browser.js#L79

And then I will make sure to call the mixin somewhere inside the asObject function here https://github.com/pinojs/pino/blob/master/browser.js#L187

Preferably when we create the initial o:

var o = Object.assign(mixin ? mixin() : {}, { time: ts, level: pino.levels.values[level] })

How is that sound?

is there anywhere else that the mixin needs to be called?

theodesp avatar Feb 03 '20 12:02 theodesp

@davidmarkclements is most familiar with the browser code. He might chime in?

jsumners avatar Feb 03 '20 12:02 jsumners

Any progress?

JunlinPan-Crypto avatar Jul 11 '22 07:07 JunlinPan-Crypto