Mar*_*son 5 javascript google-cloud-endpoints google-cloud-platform
运行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);
}
};
Run Code Online (Sandbox Code Playgroud)
您可以使用以下任一方法查看 Cloud Function 日志:
Run Code Online (Sandbox Code Playgroud)// 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; }); }
要使用 gcloud 工具查看日志,请使用 logs read 命令:
Run Code Online (Sandbox Code Playgroud)gcloud functions logs read要查看特定函数的日志,请提供函数名称作为参数:
Run Code Online (Sandbox Code Playgroud)gcloud functions logs read <FUNCTION_NAME>您甚至可以查看特定执行的日志:
Run Code Online (Sandbox Code Playgroud)gcloud functions logs read <FUNCTION_NAME> --execution-id EXECUTION_ID有关完整的日志查看选项,请查看读取日志的帮助:
Run Code Online (Sandbox Code Playgroud)gcloud functions logs read -h
您可以使用console.log()或console.error()。
console.log()命令具有INFO日志级别。console.error()命令具有ERROR日志级别。DEBUG日志级别。此处提供了有关查看 Cloud Function 日志的更多信息。
| 归档时间: |
|
| 查看次数: |
3189 次 |
| 最近记录: |