-
Notifications
You must be signed in to change notification settings - Fork 940
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
doesn't show accurate line number at web browser #105
Comments
You mean in the web browser? |
yes |
Ya... I'm not sure if there's a way around this. We may be able to fix it in V8 using the stack trace API, but don't expect anything cross-browser. |
well, I only care about Android WebView (2.2 ~ 4.4+) |
I found |
I tried out the I'm still pondering this but I'm not sure if there's a fix still... |
Yes I noticed that too. I've used bows before, and it seemed to show correct line numbers in the browser. I'm not sure what they are doing differently? |
@nicolashery Thanks for pointing to bows! It is logging correct line numbers. But I m not sure it's features complements 'debug.js' features, though. |
The issue is that logs are deferred, do they really need to be? Can we just make deferring an optional argument flag? |
What makes you think that? |
Isn't that what the stack traces shows? If I could just jump halfway up the stack trace and figure out where I called the log it would be fine. Or is it wrapped in a try catch? I don't remember, I created this issue #2975 over a year ago. |
It really just wraps the The problem is that the console will only display the call-site of the console.log() call, which always happens in the same place in debug, as opposed to the call-site of the |
@TooTallNate I meant they used to be deferred and executed in batch (like part of the $scope.$apply() stuff) This may have changed or I may have been confused from poking around the src code/stack trace, etc. Can't we just move up the stack trace to see where the debug() was called? I mean if that worked it wouldn't be an issue, but from my recollection that just isn't the case. |
Ya AFAIK they've never been deferred.
|
I use a browserify transform that overrides the console.log() and inserts the line number. Works pretty well for my purposes, except my regex doesn't handle all cases correctly. This also automates enabling of each file included in my browserify bundle (related to #154). var through = require('through2');
var _ = require('underscore');
module.exports = function(file) {
return through(function(buf, enc, next) {
var parts = file.split('/');
var filename = parts[parts.length - 1];
if (filename === 'index.js') {
filename = parts[parts.length - 2] + '-dir';
}
var bufString = buf.toString('utf8');
var lines = bufString.split(/\r\n|\r|\n/);
_.each(lines, function(line, i) {
if (line.match('console') && file.match('app')) {
var regExp = /\((.*)\)/;
var insideParens = regExp.exec(line)[1];
var lineNumber = '"Line ' + String(i + 1) + '"';
lines[i] = line.replace('(' + insideParens + ')', '(' + insideParens + ',' + lineNumber + ')');
}
});
if (file.match('app')) {
var string = "var console = {log: require('debug')('" + filename + "')}\n\n" + lines.join("\r\n");
this.push(string);
}
else {
this.push(lines.join("\r\n"));
}
next();
});
} |
👍 if we can get correct line numbers with |
That's pretty cool Nate :) On Fri, Feb 20, 2015 at 10:27 AM, Truong Nguyen [email protected]
|
In Chrome you can now have the correct file and line number by blackboxing 'debug.js' script in the DevTool; Only (quite annoying) problem is that it doesn't work if the script you blackbox is bundled together in a single file with your code. I hope chrome improves this behaviour in the future. Meanwhile it might be a good ides to expose a standalone build, since this solution won't work if you require 'debug.js' in your code. |
@wildermuthn interesting code of yours. care to make it a npm package? @TooTallNate yeah, this is tricky, tough problem to crack. any success at all yet? |
correction: bows does not seem to preserve line number |
that's a compromise i can live with for now: // workaround: since we cannot overwrite console.log without having the correct file and line number
// we'll use groupCollapsed() and trace() instead to get these.
function debug() {
console.groupCollapsed(arguments)
console.trace('Trace')
console.groupEnd()
} |
I will have to correct @binarykitchen, we just switched to bows because it indeed does indeed show the line number. |
We have an internal module we created to log stuff, it reveals the line in the source code it logged from. Policy prevents me from dumping the source code, but I can clue you into how it's done for webkit/blink and ie: isFunction (func)->
return typeof func is 'function'
class Logger
methods: [
'log', 'error', 'debug', 'trace'
]
constructor: ->
(@bind(method) for method in @methods)
bind: (method)->
target = window.console[method]
if isFunction(target) && isFunction(target.bind)
@[method] = target.bind console
else
@[method] = Function.prototype.bind.call target, console
debug = new Logger().log
debug 'module start' So the reason why debug will never show the source line number is because the exported function we all use after setting a namespace isn't a rebound function of Showing line numbers from source, will require a complete rewrite. |
I started on a possible fix for this #273. |
I just tried #273. It works. |
feel free to discuss further here. I think this should be something we handle with V3 #370 |
No description provided.
The text was updated successfully, but these errors were encountered: