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

Created on 6 Apr 2019  路  4Comments  路  Source: nodejs/node

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.

feature request util

Most helpful comment

IMO I think this should be a feature request for winston instead.

All 4 comments

(how can i put single ` in github's code...)

This way:

`` one ` backtick ``
`` or several `single` backticks ``

Rendered as: one ` backtick, or several `single` backticks.

IMO I think this should be a feature request for winston instead.

I agree with @mscdex. This would otherwise cause all code that relies upon console.log to behave differently. So using an environment variable would not be a wise choice. The spec recommends to separate things with a space even though it's allowed to deviate from it. It would theoretically be possible to add a specific util.format() option, but I'd rather not do this.

I'll keep this open a while longer to see if this request gets any traction or not.

Closing since this get no further traction. As pointed out above, it's probably best to request such a feature in winston.

Please leave a comment if someone believes this should be reopened.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sandeepks1 picture sandeepks1  路  3Comments

fanjunzhi picture fanjunzhi  路  3Comments

mcollina picture mcollina  路  3Comments

vsemozhetbyt picture vsemozhetbyt  路  3Comments

srl295 picture srl295  路  3Comments