如何使用console.log省略文件/行号 [英] How to omit file/line number with console.log
问题描述
这些天来,您可以在Chrome的控制台中编写漂亮的东西。检出
您也可以在屏幕截图中看到,文件名/行号( VM298:4
)写在右侧。是否有可能删除它,因为在我看来,这是一个很长的名称,多少或多或少破坏了我试图在控制台中产生的效果?
这很简单。您将需要使用 setTimeout
和 console.log.bind
:
setTimeout(console.log.bind(控制台,这是一个句子。)));
如果要向其应用CSS或其他文本,只需添加 %c
或任何其他%
变量:
setTimeout(console.log.bind(控制台,%c这是一个句子。, font-weight:bold;)));
var css =文字装饰:下划线;;
setTimeout(console.log.bind(控制台,%c这是一个句子。,CSS));
请注意,此方法将始终放在日志列表的末尾。例如:
console.log(日志1);
setTimeout(console.log.bind(控制台,这是一个句子。)));
console.log(日志2);
将显示为
日志1
日志2
这是一个句子。
而不是
Log 1
这是一个句子。
日志2
我希望这能回答您的问题。
In the console of Chrome you can write pretty nice stuff these days. Checkout this link. I've also made a screenshot:
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 ?
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.
这篇关于如何使用console.log省略文件/行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!