Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to omit file/line number with console.log

In the console of Chrome you can write pretty nice stuff these days. Checkout this link. I've also made a screenshot:

enter image description here

As you can see in the screenshot too, the file name / line number (VM298:4) is written at the right. Is it possible the remove that, because in my case this is a very long name and more or less breaks the effect I'm trying to make in my console ?

like image 749
Jeanluca Scaljeri Avatar asked Mar 15 '16 10:03

Jeanluca Scaljeri


People also ask

How do you wrap a Console log?

Type it and press Ctrl+Alt+W + W . Another way to console. log your variables is to simply place your mouse cursor on them and then wrap them on the line below with Ctrl+Alt+W + Down or the line above with Ctrl+Alt+W + Up .

Does Console log print a new line?

js, console. log() method is used to display the message on the console. By default, the console. log() method prints on console with trailing newline.

How do I change the line in Console?

After typing out the first line, instead of hitting enter, hit shift + enter. This will bring you the next line without executing the code.

What does Console log () do?

The console. log() is a function in JavaScript which is used to print any kind of variables defined before in it or to just print any message that needs to be displayed to the user. Syntax: console.


2 Answers

To keep your logging statements clean, you could define the following function and simply use console.print to log without filename/line numbers:

// console.print: console.log without filename/line number
console.print = function (...args) {
    queueMicrotask (console.log.bind (console, ...args));
}

console.print takes the same arguments as console.log for example:

console.print("Text with no filename info.")

console.print('%c Custom CSS and no line numbers! ', 'background: #555555; color: #00aaff');

like image 198
tapeboy7 Avatar answered Sep 23 '22 18:09

tapeboy7


Another option is to give your source script files shorter names using sourceURL

//# sourceURL=new_file_name.js 
like image 22
Darshan Avatar answered Sep 21 '22 18:09

Darshan