希望客户端Firebase日志显示在StackDriver中,而不是用户的浏览器中

问题描述

我正在使用firebase-functions/lib/logger来记录客户端Firebase / firestore活动,如

const { log,error } = require("firebase-functions/lib/logger");

export const addData = async (userId,dataId) => {
  try {
    const collectionRef = firestore
      .collection("docs")
    await collectionRef.add({
      dataId,});
    log(`Data added`,{ userId,dataId });
  } catch (err) {
    error(`Unable to add new data`,dataId });
    throw new Error(err);
  }
};

当我在本地计算机上运行此命令时,日志将显示在浏览器控制台中。这是否会发生在非本地环境中,即对于实际用户?这些日志还会自动显示在Stackdriver中还是卡在客户端上?我希望能够在Stackdriver或Firebase控制台中查看日志,但对于真实用户而言,它们不会显示在浏览器中。我该怎么做?

解决方法

登录到Cloud Functions中的消息根本不会显示在客户端应用程序中(这可能是您应用程序的安全漏洞)。它们将显示在“日志”选项卡的Cloud Functions控制台和StackDriver中。

在您的应用中登录的任何消息都不会显示在任何Google Cloud产品中。它们仅限于生成它们的设备。如果要进行云日志记录,则需要实施其他解决方案。 Cloud Functions不支持此功能-您需要研究其他解决方案或自己构建一些东西。