New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 779244 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner:
Closed: Dec 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Mac
Pri: 2
Type: Bug



Sign in to add a comment

We need a way to wrap console.log and preserve the file and line number

Reported by k...@kirkouimet.com, Oct 27 2017

Issue description

UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36

Steps to reproduce the problem:
Try to wrap console.log to do special processing on the logged arguments:

log.js ---

function customLog() {
  // Do something with the arguments besides logging them, maybe format them or store them
  ...

  // Send the output to Developer Tools
  console.log(arguments);
}

---

What is the expected behavior?
We should have some way of calling console.log() or some new console function which will allow us to drop or ignore stack frames and show the correct file and line number which called customLog(). Currently, every call to customLog will show as being from log.js in the Developer Tools.

What went wrong?
One solution to this problem is using the Developer Tools blackboxing approach which is to suppress all stack frames from log.js. The problems with this approach are:

1. It's easy to forget to configure this setting and update it per project
2. If the blackboxed file has other logic in it which we wish to log, we cannot easily log it

This guy had a great idea of being able to specify transparent stack frames as a formatting option, and being able to specify how many frames to skip:

https://bugs.chromium.org/p/chromium/issues/detail?id=231007#c19

Another approach is to create a new function on the global console object to enable this behavior.

I don't think this issue is a duplicate of the other issues as they have been closed out in favor of the blackboxing method. If there is not consensus on blackboxing being the right way to do it, we should leave this ticket open and explore implementing an alternative method.

Did this work before? No 

Chrome version: 62.0.3202.62  Channel: n/a
OS Version: OS X 10.13.0
Flash Version:
 
Cc: krajshree@chromium.org
Labels: Needs-Triage-M62 Needs-Feedback
Reporter@ - Thanks for filing the issue...!!

Could you please provide a test file with consistent reproducible steps to test the issue from TE-end.
This will help us in triaging the issue further.

Thanks...!!

Comment 2 Deleted

Project Member

Comment 3 by sheriffbot@chromium.org, Oct 30 2017

Labels: -Needs-Feedback
Thank you for providing more feedback. Adding requester "krajshree@chromium.org" to the cc list and removing "Needs-Feedback" label.

For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
Owner: l...@chromium.org
Status: Assigned (was: Unconfirmed)

Comment 6 by l...@chromium.org, Oct 30 2017

Cc: kozy@chromium.org
Thanks for the report, OP.  It looks like commenters in the bugs you've linked also believe that blackboxing a file is too aggressive of a solution, since it affects more than what you intend (just the custom logger).

To address your points,
> 1. It's easy to forget to configure this setting and update it per project
I agree that it's not very clear when/which files are blackboxed from the UI.  We should try to make this easier to setup and more clear when it is applied.

Blackboxing does require work to setup, so perhaps there is an opportunity to extend the Console API for this, as you suggest.  However, I would like to see if we can improve blackboxing first.  We might only want to hide the top callframe from the trace today, but modifying other callframes might be useful in other cases that we could support with a new API.

> 2. If the blackboxed file has other logic in it which we wish to log, we cannot easily log it
I see!  We need something that doesn't interfere with the rest of the file.  Perhaps an easy "function-level blackboxing" is what we need?  kozy@, would this be possible?

cc'ing kozy@ who may already have ideas and thoughts in this space.


As a side note, I don't use custom loggers myself, and I wonder what your use case is for wrapping console.log.  Is it to add a prefix to the message?  If we understand the use case, maybe we have other ways to support them, too :)
Thanks for the reply on Comment 6.

My main goals right now are:

1. Special formatting and additional information added to things being logged (manipulating the arguments before they hit the log)
2. Logging things to disk into a log file (when using Electron where node.js has access to the system disk)

Best,

Kirk

Status: WontFix (was: Assigned)
You need to blackbox customLog() and things would work as you expect.
Hi pfeldman,

Can we reopen this issue? Blackboxing does not seem like the best solution, you can see with my discussion with kozy@chromium.org:

---

One solution to this problem is using the Developer Tools blackboxing approach which is to suppress all stack frames from log.js. The problems with this approach are:

1. It's easy to forget to configure this setting and update it per project
2. If the blackboxed file has other logic in it which we wish to log, we cannot easily log it

This guy had a great idea of being able to specify transparent stack frames as a formatting option, and being able to specify how many frames to skip:

https://bugs.chromium.org/p/chromium/issues/detail?id=231007#c19

Another approach is to create a new function on the global console object to enable this behavior.

I don't think this issue is a duplicate of the other issues as they have been closed out in favor of the blackboxing method. If there is not consensus on blackboxing being the right way to do it, we should leave this ticket open and explore implementing an alternative method.

---

Best,

Kirk

Sign in to add a comment