-
Notifications
You must be signed in to change notification settings - Fork 139
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
Make the stack trace and/or line number available #1
Comments
We definitely want to add line numbers. However, unfortunately, the nature of wrapping There are a number of possible solutions we are considering to address this. For example, if we change the exports at the bottom of the script to something like the following:
Then you could call the following and still get line numbers:
If you didn't want the text to be formatted, you could still call:
Of course, having to wrap your string in a On a related note, there may be some potential changes coming to https://code.google.com/p/chromium/issues/detail?id=167911 |
Hi Adam, I came up with a simple hack to enable logging line numbers. I have only tested it in Chrome though. Here's how it works:
I could've also added two Limitations:
See source here: https://github.com/fleon/log/blob/master/log.coffee |
This is fantastic work. Very clever. However, before merging I'd like to take the following steps.
Thanks for your contribution! |
I managed to get it working in Firefox+Firebug as well, but the hack is very ugly. It works without Each log statement now shows up the filename and actual line number overlayed on top of the log.js line number (thanks to Firebug allowing Nevertheless, this was a lot of fun! Source: https://github.com/fleon/log/commit/0713275eae0f2ccfcd7f963016c4febd0e659cb7 (warning: ugly code) |
Another option, although not as independent, is to combine log.js with stacktrace.js. Here's the modified _log = function() {
if (typeof window.printStackTrace === 'function') {
var trace = printStackTrace();
var callerLine = trace[trace.length-1];
var index = callerLine.indexOf("at ");
var clean = callerLine.slice(index+2, callerLine.length);
}
var array = makeArray(arguments);
if (clean) { array.push(clean); }
return console.log.apply(console, array);
}; Assuming you have included |
See my fork at https://github.com/6twenty/log/commit/249864da2a39d80f7abd4774a11d8858a40af37c for a working example (coffeescript version updated too, but with a typo which is fixed in https://github.com/6twenty/log/commit/5f0f16820eb35c060e42dbf41a6ef8db4a5266d6). |
you could do something like
or this:
which would output nothing if you missed of the trailing |
@SamHasler Thanks! Those are both very interesting options. The The other approach is very tempting, but I think it's a little too tricky for our average user. I would worry too many people would miss the subtlety of the extra One of these will likely get us there though, so thanks again! |
The user can turn on Chrome Dev Tools Settings > General > Sources > However it doesn't help if they concatenate log.min.js into thier own code. See also: jsbin/jsbin#1833 |
Thanks @SamHasler. Didn’t know about that setting. 👍 |
@SamHasler thanks for the tips with md() how we can remove the bracket and first " ? |
Possibly do something like this:
https://github.com/eriwen/javascript-stacktrace
Or like this:
__LINE__ = (new Error).stack.split("\n")[1].match(/:([0-9]+):/)[1]
https://news.ycombinator.com/item?id=5540763
See https://news.ycombinator.com/item?id=5540716 for more information.
The text was updated successfully, but these errors were encountered: