You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the log message matches the splat regex, the behavior of the logging changes even if the splat formatter is not used. Any meta data passed to the logger is not passed through to the underlying transport when the regex matches.
Given a logger created with a transport configured not to use the splat formatter:
const log = winston.createLogger({
level: 'debug',
transports: [
new ConsoleTransport({
format: winston.format.combine(
winston.format.timestamp(),
winston.format.printf(info => {
// ... do something with `info`
}),
),
}),
],
});
The following works as expected, extraThing is available as a property of the info object in the transport.
log.info('this is a test', { extraThing: 7 });
The following unexpectedly does not include extraThing as a property of the info object in the transport.
When not using the splat formatter, the splat regex should not be tested against the message, and the behavior should not vary by the content of the message.
The text was updated successfully, but these errors were encountered:
murrayju
added a commit
to murrayju/winston
that referenced
this issue
Oct 1, 2019
Verified that this issue still exists in the latest version of Winston. I think a proper resolution of this may warrant a larger discussion to determine the most appropriate solution. I have not tested the implementation in #1710 although it seems odd to me that the logger instance does a determination on splat behavior and makes some assumptions on it rather than just passing all the necessary data to the formatter itself for the transformation.
MWE that proves this is still an issue:
constlogger=winston.createLogger({level: "debug",defaultMeta: {id: 'APP',service: 'Authentication'},transports: [mockTransports.inMemory(actualOutput)]});logger.info('this is a test',{extraThing: 7});logger.info('this is %c a test',{extraThing: 7});assume(actualOutput.every((msg)=>msg.hasOwnProperty("extraThing"))).is.true("Not all messages include the additional metadata")
Edit: While this issue is related to our metadata master issue the root cause is not metadata related. Instead this is an issue with the backwards compatability hotpath optimizations. As such I'm removing it from the list of referenced issues in #2029.
Please tell us about your environment:
winston
version?winston@2
winston@3
node -v
outputs: v12.11.0What is the problem?
If the log
message
matches the splat regex, the behavior of the logging changes even if the splat formatter is not used. Any meta data passed to the logger is not passed through to the underlying transport when the regex matches.Given a logger created with a transport configured not to use the splat formatter:
The following works as expected,
extraThing
is available as a property of theinfo
object in the transport.The following unexpectedly does not include
extraThing
as a property of theinfo
object in the transport.Complete running example on runkit:
https://runkit.com/murrayju/winston-format-behavior
What do you expect to happen instead?
When not using the splat formatter, the splat regex should not be tested against the message, and the behavior should not vary by the content of the message.
The text was updated successfully, but these errors were encountered: