How to omit file/line number with console.log
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');
This is pretty simple to do. You will need to use setTimeout
with a console.log.bind
:
setTimeout (console.log.bind (console, "This is a sentence."));
And if you want to apply CSS or additional text to it just add add %c
or any other %
variable:
setTimeout (console.log.bind (console, "%cThis is a sentence.", "font-weight: bold;"));
var css = "text-decoration: underline;";
setTimeout (console.log.bind (console, "%cThis is a sentence.", css));
Note that this method will always be placed at the end of the log list. For example:
console.log ("Log 1");
setTimeout (console.log.bind (console, "This is a sentence."));
console.log ("Log 2");
will appear as
Log 1
Log 2
This is a sentence.
instead of
Log 1
This is a sentence.
Log 2
I hope this answers your question.