question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Object colors with a plurality of parameters

See original GitHub issue

When one does

debug({a:1, b:2});

the object properties’ values are printed with colours

image

but when one does

debug("string", {a:1, b:2});

colours are gone

image

just FYI

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
chagriscommented, Dec 14, 2018

Yeah, my guess was that it was this way for historical reasons (util.format() has a %O since v.8.4.0)

It’d be more or less easy to have it colored one way or another (debug uses the ...args rest parameters) and the current code is pretty similar to what you proposed:

	args[0] = createDebug.coerce(args[0]);

	if (typeof args[0] !== 'string') {
		// Anything else let's inspect with %O
		args.unshift('%O');
	}

If it’s not starting with a string, this part could add as many %O as there are arguments in one string that is unshifted, but if there’s one it’d need to parse the string, count the already-existing (valid) %* placeholders and add more as needed. (also since Node v10.0 there’s util.formatWithOptions which could automatically color everything but that’d break a lot of code that isn’t running on a recent Node?)


However, there’s currently https://github.com/visionmedia/debug/issues/582 which aims to give more control over the output format, and ultimately, if possible, to get rid of DEBUG_COLORS and the use of isatty(), which’d require changes to how the %O and %o decide to (/ are made to) color their output… If you have any idea about that, would be great to hear!


For now, an already supported way would be to simply override the log method to, for example, console.log

const debug = require('debug');
debug.log = console.log.bind(console);
log('All those objects will be colored (if you run on a recent enough Node version)', {foo: 'bar'}, {foo: 'bar'});
1reaction
jfoclpfcommented, Dec 14, 2018

@Qix- I see the problem and thank you guys for the reply, but how come is the intended behaviour?

Why simply not

if (typeof args[0] === "string"){
  args[0] += " %0";
}

Am I missing anything here?

Read more comments on GitHub >

github_iconTop Results From Across the Web

WO2001052176A3 - A method of analyzing a plurality of objects ...
These objects may inter alia be represented by colour pixels in an image ... by a plurality of parameters, e.g. the intensities of...
Read more >
Method and apparatus for generating a plurality of parameters of an ...
The electrical images from the color camera 12 are processed by the image processor 10 to form a plurality of different representations of...
Read more >
OpenAPI Specification - Version 3.0.3 - Swagger
OpenAPI Specification. Version 3.0.3. The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", ...
Read more >
Assessment of Segmentation Parameters for Object-Based ...
The main objective of this study is to assess OBIA segmentation and classification accuracy depending on shape-color, compactness-smoothness, and band weight ...
Read more >
Use parameters to highlight data points in VA reports
Color is a powerful data visualization tool. ... Create parameters and assign to control objects; Create Calculated item flag to represent ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found