console.error([data][, ...args])
使用换行符打印到 stderr
。可以传递多个参数,第一个用作主要消息,所有附加参数用作类似于 printf(3)
的替换值(参数全部传递给 util.format()
)。
¥Prints to stderr
with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to printf(3)
(the arguments are all passed to
util.format()
).
const code = 5;
console.error('error #%d', code);
// Prints: error #5, to stderr
console.error('error', code);
// Prints: error 5, to stderr
如果在第一个字符串中找不到格式化元素(例如 %d
),则在每个参数上调用 util.inspect()
并将结果字符串值连接起来。有关详细信息,请参阅 util.format()
。
¥If formatting elements (e.g. %d
) are not found in the first string then
util.inspect()
is called on each argument and the resulting string
values are concatenated. See util.format()
for more information.