-
Notifications
You must be signed in to change notification settings - Fork 97
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
Try better fix for #1485 #57
Conversation
@indexzero some tests fail but because they're assuming info.meta rather than meta params being merged into info which seems to be what happens otherwise (but only with splat...). What is the desired behavior? |
I have been recently poking around as the meta params being merged into info also caused me an issue and came across this PR. I think this issue is identical to the one I raised (winstonjs/winston#1510), but is also related to winstonjs/winston#1486. Only linking so they can all be closed at the same time. It only happens if it's the first splat parameter that is an object. I'm still trying to get me head around why this is desired. I am guessing it's for backward compatibility, but I thought the old logging used the last object as the meta, not the first? |
IMHO this is polluting the Is it not better to handle the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glad we got to the bottom of this head scratcher today @DABH. Let's add test for splat
to cover the scenarios that we discussed:
let transports = {
console: new winston.transports.Console({level: 'info'})
};
let {format} = winston;
let logger = winston.createLogger({
format: format.combine(
format.splat(),
format.simple()
),
transports: [transports.console]
});
logger.log(
'info',
'any message',
{ label: 'label!' }
);
logger.log(
'info',
'let\'s %s some %s',
'interpolate',
'splat parameters',
{ label: 'label!' }
);
const terr = new Error('lol please stop doing this');
terr.enum = true;
logger.log(
'info',
'any message',
terr
);
logger.log(
'info',
'let\'s %s some %s',
'interpolate',
'splat parameters',
terr
);
logger.log(
'info',
'first is a string %s [[%j]]',
'behold a string',
{ lol: 'what did charlie do' }
);
logger.log(
'info',
'first is an object [[%j]]',
{ lol: 'what did charlie do' }
);
👍 once we have test coverage.
I can no longer log a single object as a splat:
logger.info('hey %O', obj);
doesn't format the splat right anymore...
But I also want this to work:
This PR and an associated one in winston make both of these cases work, but @indexzero would be good if you could opine. IIRC in 3.x we shouldn't be assigning to info.meta like this...