Skip to content

Meta properties omitted if message matches splat regex #1709

@murrayju

Description

@murrayju

Please tell us about your environment:

  • winston version?
    • winston@2
    • winston@3
  • node -v outputs: v12.11.0
  • Operating System? Linux
  • Language? ES6

What 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:

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.

log.info('this is %c a test', { extraThing: 7 });

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.

Metadata

Metadata

Assignees

Labels

BugFormatsApplies to the implementation of FormatsGroomedIssue has been reviewed and is ready for handlingMetadataApplies to Metadata behavior

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions