How to omit file/line number with console.log

Viewed 4217

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 ?

4 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');

Use queueMicrotask with console.log.bind to loose the source file info when logging:

queueMicrotask (console.log.bind (console, "Look! No source file info..."));

Queuing microtasks will maintain order of the logging if there are multiple calls, while setTimeout is not guaranteed to execute tasks in order.

Related