我想查看Cloud Firestores日志,就像看到Firebase的Cloud Functions一样.Firebase控制台的功能"选项卡中有一个日志"选项卡.同样,我想在Cloud Firestore中看到这一点.怎么样?
I want to see Cloud Firestores logs like I can see for Cloud Functions for Firebase. There is a logs tab in Functions tab of the Firebase console. Similarly I want to see this for Cloud Firestore. How?
推荐答案我编写了一个Firebase云函数,用于将所有活动记录到Firestore:
I wrote a firebase cloud function to log all activity to 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}); } });
这是记录的数据的示例:
Here's an example of the logged data:
请注意,这是一个仅记录所有内容的快速开发人员版本;在生产中,我们有Firestore规则来拒绝对表的任何读/写(firebase函数的管理员仍然可以访问它们):
Note that this is a quick dev only version that logs everything; in production we have Firestore rules to deny any read / write to the table (the admin on firebase functions can still access them):
// firestore.rules match /firestore_log/{entryId} { allow read: if false; allow write: if false; }并过滤记录的集合,以避免持久保存敏感数据.
and filter the logged collections to avoid persisting sensitive data.
请注意,如果您希望将其保留在日志中而不是Firestore中,则可以使用 console.log({....}).我更喜欢Firestore,因为它旨在处理更大的数据集.
Note that if you prefer to persist this in the logs instead of Firestore you can use console.log({....}). I prefer Firestore because its designed to handle larger data sets.
更多推荐
如何查看Cloud Firestore日志?
发布评论