使用 Node StackDriver Client Library 时如何登录到不同级别?

How To Log to Different Level when Using Node StackDriver Client Library?

我正在使用 StackDriver client library,但无法找到一种方法使其记录到 INFO、WARN、ERROR 等...

谁能推荐一下?

找到答案了。只需在创建条目之前将 serverity 放入元数据即可。

const { Logging } = require('@google-cloud/logging');
const logging = new Logging({ projectId: "proj1" });
const log = logging.log("proj1", { removeCircular: true });

const metadata = {
    resource: {type: 'global'},
    severity: 'CRITICAL' // << HERE WHERE WE SHOULD PUT LOG LEVEL
};
const entry = log.entry(resource, "something happened");
log.write(entry);

可用级别为 DEFAULTDEBUGINFONOTICEWARNINGERRORCRITICALALERTEMERGENCY

参考资料