Skip to content

Add capacity to specify separator for util.format(), instead of space ' '. #27114

@UnightSun

Description

@UnightSun

Is your feature request related to a problem? Please describe.
Many logger use util.format as the underlying implementation. e.g winston.logger.
So
logger.warn(1, 2, 3);
got result: 1 2 3
This is ok when log is simple, but for real world, space separated log is not easy to analysis.
I have to write like
logger.warn(v0 + '|' + v1 + '|' + v2);
or
logger.warn(``${v0}|${v1}|${v2}``); (how can i put single ` in github's code...)

Describe the solution you'd like
Consider add an env variable like process.env.NODE_FORMAT_SEPARATOR

code node/lib/internal/util/inspect.js line: 1541

  while (a < args.length) {
    const value = args[a];
    str += join;
    str += typeof value !== 'string' ? inspect(value, inspectOptions) : value;
    join = ' ';
    a++;
  }

can be

  const sepor = process.env.NODE_FORMAT_SEPARATOR || ' ';
  while (a < args.length) {
    const value = args[a];
    str += join;
    str += typeof value !== 'string' ? inspect(value, inspectOptions) : value;
    join = sepor;
    a++;
  }

Describe alternatives you've considered
or just add a function to util to specify separator.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.utilIssues and PRs related to the built-in util module.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions