Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create shortcut to console.log() in Chrome

Because I'm lazy, I created a function log that basically is just an abbreviation of console.log:

function log() {   console.log.apply(console, arguments); } 

Whenever I call this, I see the logged item in Google Chrome's Developer Tools, with on the right hand side the line number where the item was logged. However, this line number is always the same, because the actual console.log call is located at one specific place in the code (namely where I declare the log function as above).

What I also tried is just:

var log = console.log; 

but this always throws an error: Illegal invocation. Weird, but I guess that's not a possibility.

How can I make a shortcut to console.log, with Developer Tools showing the line number where log was called, rather than where the actual console.log call is located?

like image 226
pimvdb Avatar asked Mar 28 '11 09:03

pimvdb


People also ask

How do I pull up console log in Chrome?

To open the developer console in Google Chrome, open the Chrome Menu in the upper-right-hand corner of the browser window and select More Tools > Developer Tools. You can also use Option + ⌘ + J (on macOS), or Shift + CTRL + J (on Windows/Linux).

How do I add console log to my browser?

Adding a console log is something Google recently add. In the selected row instead of left click,click right click and select 'add logpoint', a small text box will pop up, enter the variable you want you console log. If you do not see this feature update your browser. Thanks for the answer!

How do I make an automated shortcut in Chrome?

To add shortcut links to the sites on the Home screen with Chrome Android, firstly launch the site whose link you wish to add to the Home screen. Now, tap on the three dots>Add to home screen>Add. This will automatically add the shortcut link to the home screen of your Android phone.


1 Answers

When I reported it, it was refused but the answer was simple - create the shortcut like this:

var log = console.log.bind(console); 

This doesn't leave out the line number, whilst you can call it like log(...).

like image 131
pimvdb Avatar answered Oct 03 '22 01:10

pimvdb