Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util.inspect multiline output length limit should be configurable #7305

Closed
shreyagarwal opened this issue Jun 15, 2016 · 7 comments
Closed
Labels
feature request Issues that request new features to be added to Node.js. util Issues and PRs related to the built-in util module.

Comments

@shreyagarwal
Copy link

shreyagarwal commented Jun 15, 2016

Version: v4.4.5
Platform: Darwin MacBook-Air.local 14.3.0 Darwin Kernel Version 14.3.0: Mon Mar 23 11:59:05 PDT 2015; root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64
Subsystem: util : util.js#L815:

The limit is 60 . Can this be configurable ?
Or is there any potentially foolproof way to log any type of variables in a single line for logging purposes.

P.S> would be happy to submit PR in desired format if this is is acknowledged.

@mscdex mscdex added util Issues and PRs related to the built-in util module. feature request Issues that request new features to be added to Node.js. labels Jun 15, 2016
@Trott
Copy link
Member

Trott commented Jun 15, 2016

It would be great to see a PR that adds a property to the options object that allows the user to configure the maximum length, perhaps allowing a setting of 0 to disable the limit.

cjihrig added a commit to cjihrig/node that referenced this issue Jul 5, 2016
This commit adds a breakLength option to util.inspect(). This
option allows users to control the length at which object keys
are split across multiple lines. For backwards compatibility,
this option defaults to 60.

Fixes: nodejs#7305
PR-URL: nodejs#7499
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Fishrock123 pushed a commit that referenced this issue Jul 6, 2016
This commit adds a breakLength option to util.inspect(). This
option allows users to control the length at which object keys
are split across multiple lines. For backwards compatibility,
this option defaults to 60.

Fixes: #7305
PR-URL: #7499
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
@whitneyland
Copy link

whitneyland commented Mar 4, 2017

By setting breakLength to 1, shouldn't this create multiple lines in the output? I'm getting a single line string like this:
{ color: 'black', 'font-size': '12px', 'font-weight': 'bold' }

util.inspect(
{
    "color": "black", 
    "font-size": "12px", 
    "font-weight": "bold"},
{
    "showHidden" : false,
    "depth" : 4,
    "showProxy" : false,
    "maxArrayLength" : 10,
    "breakLength" : 1,
})

@BridgeAR
Copy link
Member

@whitneyland I get the following output '{ color: \'black\',\n \'font-size\': \'12px\',\n \'font-weight\': \'bold\' }'. This is correct as the output will only break for each element.

If the documentation is not clear enough about this, could you please open a issue for this?

@windmaomao
Copy link

Setting breakLength to 1 is working, but not for any number more than 80 including Infinity. This can be confirmed if you use console.dir, which will print out all the \n.

@BridgeAR
Copy link
Member

@windmaomao I just checked and it does work properly for me. Do you have a concrete example that does not work as expected? And what Node.js version do you use?

@windmaomao
Copy link

@BridgeAR the node version is 14.15.3, but i have tried with couple of different version as well, so it's pretty consistent.

Here's how to reproduce it, if you use the following code and then try to set breakLength to 1, it'll make the array to display as a column, however if you change this number to anything else, I always get a break after 5 items.

const util = require('util')

const settings = {
//	showHidden: false, 
	depth: null,
	colors: true,
	maxArrayLength: Infinity,
//	maxStringLength: Infinity,
	breakLength: 1,
//	compact: false
}

util.inspect.defaultOptions = {
	...util.inspect.defaultOptions,
	...settings
}

const log = (s, options = {}) => { 
	console.log(util.inspect(s, options))
}

module.exports = log

log([1,2,3,4,5,6,7])

@BridgeAR
Copy link
Member

If I understood correct, you prefer to deactivate the array grouping functionality. It's possible to set compact = true or compact = 0. It'll stop the grouping functionality but it'll also change a few other formatting aspects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

No branches or pull requests

6 participants