2

I found this question which is "close" to what I'm looking for:

How to get result of console.trace() as string in javascript with chrome or firefox?

However, is there a way to actually replace which JS file (and line number) the log entry originates from?

enter image description here

I'm funneling all my debug traces through another method, so no matter what I log/trace, it always shows up as the same file:line# (and once clicked on, there's no way to traverse the stack / code like you can during a live debug session).

I could try to simply log the stack Error.captureStackTrace(obj, trace); immediately after the given object (since concatenating them in the same trace would treat them as Strings, instead of clickable log entries), but I'm hoping there's a way to hijack Chrome's console a bit :)

Community
  • 1
  • 1
chamberlainpi
  • 4,854
  • 8
  • 32
  • 63
  • For a production level i had a different approach. Instead of trying to hide only parts of the trace. I hijacked the console so anything that is in production and has `console.log` `trace` `warn` `dir`, etc. would be stored in an object without actually calling the console.log. So this way every error is stored in an Object which can be either emptied, either sent to our servers. We did this also because most of us, developers, were suffering from tourette syndrome and most of the logs were not business/user/boss friendly. – helly0d Jan 23 '15 at 00:43
  • Also as far as i know, there is no other way of hijacking the console stack trace so that the file or line number would be different. Even if you manage to do this, what would be the point ? Firstly an experienced user ( programmer ) would be able to see that you have hijacked the console and he could hijack the console in an earlier stage using a bookmarklet. Secondly, you will never be able to hijack the core errors (i.e. net::ERR_BLOCKED_BY_CLIENT ). We have tried to catch the net errors so that the boss won't get alarmed that "Look there is an error" even though we were handling it. – helly0d Jan 23 '15 at 00:49

1 Answers1

0

This may not be exactly what you were looking for but you can use Image().src to silently send copies of errors to your server if you wanted to capture them there for reporting/logging purposes?

Here's how one guy is doing it with Ext JS, but the Image().src bit is plain javascript (I think!):

http://www.sencha.com/forum/showthread.php?295768-Basic-error-handling-for-Ext-JS-apps

Marc Fearby
  • 1,305
  • 1
  • 13
  • 28
  • I don't think that this is what he was actually asking. He was asking if is there any way to completely hijack the console so that a normal user can't trace the stacks of the logs debugs or errors. – helly0d Jan 23 '15 at 00:39