gpt4 book ai didi

javascript - Google Cloud 功能的 console.log 信息显示在哪里

转载 作者:搜寻专家 更新时间:2023-11-01 04:22:34 25 4
gpt4 key购买 nike

当我运行 Google Cloud 函数时,如何查看 console.log 打印?有云控制台吗?

exports.helloWorld = function helloWorld(req, res) {
// Example input: {"message": "Hello!"}
if (req.body.message === undefined) {
// This is an error case, as "message" is required.
res.status(400).send('No message defined!');
} else {
// Everything is okay.
console.log(req.body.message);
res.status(200).send('Success: ' + req.body.message);
}
};

最佳答案

Viewing Logs

您可以使用以下任一方法查看 Cloud Functions 日志:

// By default, the client will authenticate using the service account file
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
// the project specified by the GCLOUD_PROJECT environment variable. See
// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication
const Logging = require('@google-cloud/logging');

function getLogEntries () {
// Instantiates a client
const logging = Logging();

const options = {
pageSize: 10,
filter: 'resource.type="cloud_function"'
};

// Retrieve the latest Cloud Function log entries
// See https://googlecloudplatform.github.io/gcloud-node/#/docs/logging
return logging.getEntries(options)
.then(([entries]) => {
console.log('Entries:');
entries.forEach((entry) => console.log(entry));
return entries;
});
}

To view logs with the gcloud tool, use the logs read command:

gcloud functions logs read

To view the logs for a specific function, provide the function name as an argument:

gcloud functions logs read <FUNCTION_NAME>

You can even view the logs for a specific execution:

gcloud functions logs read <FUNCTION_NAME> --execution-id EXECUTION_ID

For the full range of log viewing options, view the help for logs read:

gcloud functions logs read -h

Writing Logs

您可以使用 console.log()console.error()

  • console.log() 命令具有 INFO 日志级别。
  • console.error() 命令具有 ERROR 日志级别。
  • 内部系统消息具有 DEBUG 日志级别。

有关查看 Cloud Function 日志的更多信息可用 here .

关于javascript - Google Cloud 功能的 console.log 信息显示在哪里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44556308/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com