Node.js console.log与console.info [英] Node.js console.log vs console.info

查看:128
本文介绍了Node.js console.log与console.info的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 console.log vs console.info 有什么好处?
或者其他任何控制台命令?

What is the benefit of using console.log vs console.info? Or any of the other console commands for that matter?

console.info("info");
console.error("error");
console.warn("warn");

vs

console.log("log");

我认为它可能会改变输出的颜色或连接某种标签,但它们似乎都做同样的事情。根据此处的文档:

I thought it might change the color of the output or concatenate some sort of label, but they seem to all do the same thing. And according to the documentation here:

https ://nodejs.org/api/console.html#console_console_info_data

它们似乎都与 console.log相同

推荐答案

根据您链接到的文档, console.error console.warn 输出到 stderr 。其他输出到 stdout

According to the documentation that you linked to, console.error and console.warn outputs to stderr. The others output to stdout.

如果从节点进行管道或重定向。 js 区别很重要。

在浏览器和节点中都编写了很多JavaScript。 JS 。让节点实现完整的控制台可以实现更好的代码交叉兼容性。

There is a lot of JavaScript written to run in both the browser and Node.js. Having node implement the full console allows for greater code cross-compatibility.

在大多数浏览器中,不仅可以使用不同的颜色登录,还可以过滤以查看具体的消息。

In most browsers, not only do these log in different colors, but you can also filter to see specific messages.

console.info("info");
console.error("error");
console.warn("warn");
console.log("log");

这篇关于Node.js console.log与console.info的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆