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

Allow line numbers to match debug() call in browser consoles #273

Closed

Conversation

fijiwebdesign
Copy link

A possible starting point to fixing file and line number mapping in the browser, #198 as well as for sourcemaps with browserify and webpack, #223

I'm not sure what of the full formatting scope that is done in enabled() or if it can be integrated into this approach for matching line numbers. This approach has the limitation that it needs to do formatting up front when debug() is called. This is because debug() has to return console.log() directly. i.e: return console.log.bind(console, '%c%s +%sms', 'color: ' + self.color, namespace, interval) to preserve line numbers.

This limits to using bind() to add formatting to console.log().

Currently it supports the color formatting of namespace and ms interval. The ms interval is now directly after the namespace due to limitation that we can only prepend arguments to Function.prototype.bind().

@neojp
Copy link

neojp commented May 2, 2016

👍 I wish this was merged. Thanks @fijiwebdesign

@TooTallNate
Copy link
Contributor

Very clever, but as you mention it has the limitation that formatters are disabled, which is probably a no-go, or at least a major version bump.

@TooTallNate
Copy link
Contributor

TooTallNate commented May 5, 2016

I think we could make something like debug('foo %s')('bar') would, where the middle function call returns the bound console.log function with the formatter appended. Would be slower for sure, and a breaking API change.

@jabaz
Copy link

jabaz commented Jun 25, 2016

This works well, but setting color manually, has no effect!

@thebigredgeek
Copy link
Contributor

@jabaz can you explain?

@thebigredgeek thebigredgeek added the discussion This issue is requesting comments and discussion label Nov 14, 2016
@thebigredgeek thebigredgeek added this to the 2.5.0 milestone Nov 14, 2016
@thebigredgeek thebigredgeek added change-minor This proposes or provides a change that requires a minor release feature This proposes or provides a feature or enhancement labels Nov 14, 2016
@thebigredgeek
Copy link
Contributor

#370

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
change-minor This proposes or provides a change that requires a minor release discussion This issue is requesting comments and discussion feature This proposes or provides a feature or enhancement
Development

Successfully merging this pull request may close these issues.

5 participants