【发布时间】:2019-08-24 21:50:30
【问题描述】:
我已经搜索过,但没有找到关于这个问题的任何内容。
我已经部署了一些用 JavaScript 编写的 Google Cloud 函数,它们利用以下函数来报告错误。函数运行成功,但我收到以下错误:
TypeError: logging.log 不是函数 在 reportError (/user_code/index.js:158:23)
const logging = require('@google-cloud/logging');
报告错误函数:
function reportError(err, context = {}) {
const logName = 'errors';
const log = logging.log(logName);
// https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/MonitoredResource
const metadata = {
resource: {
type: 'cloud_function',
labels: {function_name: process.env.FUNCTION_NAME},
},
};
// https://cloud.google.com/error-reporting/reference/rest/v1beta1/ErrorEvent
const errorEvent = {
message: err.stack,
serviceContext: {
service: process.env.FUNCTION_NAME,
resourceType: 'cloud_function',
},
context: context,
};
// Write the error log entry
return new Promise((resolve, reject) => {
log.write(log.entry(metadata, errorEvent), (error) => {
if (error) {
return reject(error);
}
return resolve();
});
});
}
// [END reporterror]
【问题讨论】:
-
对于初学者,您应该提供有关“日志记录”变量如何初始化的更多上下文。
-
道歉 - 我已经更新了我上面的问题。
标签: javascript google-cloud-functions