如何查看Cloud Firestore日志?

编程入门 行业动态 更新时间:2024-10-28 16:17:48
本文介绍了如何查看Cloud Firestore日志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想查看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日志?

本文发布于:2023-11-22 05:12:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616099.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日志   Cloud   Firestore

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!