gpt4 book ai didi

firebase - 如何查看 Cloud Firestore 日志?

转载 作者:行者123 更新时间:2023-12-04 21:31:04 26 4
gpt4 key购买 nike

我想查看 Cloud Firestores 日志,就像我可以看到的 Cloud Functions for Firebase 日志一样。 Firebase 控制台的函数选项卡中有一个日志选项卡。同样,我想在 Cloud Firestore 中看到这一点。如何?

最佳答案

我编写了一个 Firebase 云函数来将所有事件记录到 Firestore:

/**
* Logs all database activity
*
* @type {CloudFunction<Change<DocumentSnapshot>>}
*/
exports.dbLogger = functions.firestore
.document('{collection}/{id}')
.onWrite(async (change, context) => {
const {collection, id} = context.params;
if (collection !== 'firestore_log') {
const event = context.eventType;
const data = change.after.data();
const created_at = Date.now();
admin.firestore().collection('firestore_log').add({collection, id, event, data, created_at});
}
});


以下是记录数据的示例:

firestore_log entry

请注意,这是一个仅用于记录所有内容的快速开发版本;在生产中,我们有 Firestore 规则来拒绝对表的任何读/写(firebase 功能的管理员仍然可以访问它们):
// firestore.rules
match /firestore_log/{entryId} {
allow read: if false;
allow write: if false;
}

并过滤记录的集合以避免持久保存敏感数据。

请注意,如果您更愿意将其保存在日志中而不是 Firestore 中,您可以使用 console.log({....}) .我更喜欢 Firestore,因为它旨在处理更大的数据集。

关于firebase - 如何查看 Cloud Firestore 日志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51588931/

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