【问题标题】:How can I see Cloud Firestore logs?如何查看 Cloud Firestore 日志?
【发布时间】:2018-07-30 07:25:21
【问题描述】:

我想查看 Cloud Firestores 日志,就像我在 Cloud Functions for Firebase 中看到的那样。 Firebase 控制台的 Functions 选项卡中有一个日志选项卡。同样,我想为 Cloud Firestore 看到这个。怎么样?

【问题讨论】:

    标签: firebase google-cloud-firestore


    【解决方案1】:

    我编写了一个 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 规则来拒绝对表的任何读/写(firebase 功能的管理员仍然可以访问它们):

    // firestore.rules
    match /firestore_log/{entryId} {
        allow read: if false;
        allow write: if false;
    }
    

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

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

    【讨论】:

      【解决方案2】:

      目前没有向开发人员公开 Cloud Firestore 的日志条目,因此我们暂时建议您单独记录您所了解的所有统计信息。

      【讨论】:

      • 在数据泄露/调查的情况下,这些日志是否可用 Dan?
      • @dan-mcgrath 我们能得到答案吗?
      • Firestore 日志可能不会暴露,但设置日志级别的能力是...firebase.google.com/docs/reference/js/…
      猜你喜欢
      • 1970-01-01
      • 2019-10-15
      • 2012-09-01
      • 1970-01-01
      • 2019-10-27
      • 1970-01-01
      • 2016-12-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多