Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

util.inspect() on process.config() and os.networkInterfaces() contains escaped line breaks "\n" #6943

Closed
HansHammel opened this issue Jan 22, 2014 · 8 comments

Comments

@HansHammel
Copy link

  1. problem: log entries contain "\n" instead of line breaks
  2. problem: while on windows, line break should be "\r\n"

reproduced like so:

Logger.info('PROCESS: ' + util.inspect(process.config, {
  showHidden: false,
  depth: null,
  colors: false,
  customInspect: false
}));

outputs in log file:

{"level":"info","message":"PROCESS: { target_defaults: \n   { cflags: [],\n     default_configuration:      [...]

should be:

{"level":"info","message":"NETWORK: { target_defaults: 
   { cflags: [],
     default_configuration:      [...]

Logger is a Winston File Logger
while e.g. util.inspect(process.memoryUsage())); and others are fine, the output of util.inspect(os.networkInterfaces()) and util.inspect(process.config()) are broken (^)

Maybe a Winston problem (Winston uses unix line breaks only) !?

@indutny
Copy link
Member

indutny commented Jan 22, 2014

That's because output in log file is generated using JSON.stringify() (I guess?), doesn't seem to be a bug. Please use mailing list for further discussion of this question.

@indutny indutny closed this as completed Jan 22, 2014
@trevnorris
Copy link

Go to your console and do the following:

console.log(util.inspect(process.config, {
  showHidden: false,
  depth: null,
  colors: false,
  customInspect: false
}));

You'll see that the output appears normally. Whereas if you remove console.log() it displays as you've shown above.

So I don't think it's a JSON.stringify() thing. I'm going to reopen and assign to myself as a reminder to look later.

@trevnorris trevnorris reopened this Jan 23, 2014
@ghost ghost assigned trevnorris Jan 23, 2014
@thomseddon
Copy link

It's because the total output length is over 60 chars, according to: https://github.com/joyent/node/blob/master/lib/util.js#L434

You can recreate this with:

util.inspect({
  hello: 'world',
  foo: 'barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr',
});

Perhaps there should be an option to disable this, for example: thomseddon@0554bfc?

@thomseddon
Copy link

Sorry here's the diff: https://github.com/thomseddon/node/compare/format-wrap

@trevnorris
Copy link

@thomseddon Ah, thanks.

@tjfontaine what do you think? make that a configurable?

@thomseddon
Copy link

Just to chime in - the shout for this being configurable would be that if you don't want to output the message in your terminal (such as when logging as in this example) you would disable wrapping.

@tjfontaine
Copy link

I am all for taking anything we have as a predefined constant and moving that into a default for options. And util.inspect already supports objects with custom inspect methods including being able to get the options that were passed in.

Hopefully once we've moved all of our assumptions into defaults on the options object there will be no more need for us to tweak the interface aside from our own needs.

@jasnell
Copy link
Member

jasnell commented May 28, 2015

Marking this as a feature request as it does not actually appear to be a bug. Rather, the discussion aims towards making the line length configurable somehow.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants