簡體   English   中英

從具有Cloud功能的Firebase仿真器進行日志記錄

[英]Logging from emulator with Cloud Functions for Firebase

我正在嘗試在index.js中調試Cloud Function。 看起來像這樣:

exports.minutely_tick =
  functions.pubsub.topic('minutely-tick').onPublish((event) => {
    console.log('This job runs every minute');
    getData("myParameter")
    .then((data) => {
        return console.log('Data is ', data);
      })
      .catch((error) => {
        return console.log('Error is: ', error);
      });
  });

我已經啟動了Cloud Functions Emulator,它成功地准備了模擬功能。

..但是當我執行minutely_tick這樣的雲功能仿真器中:

firebase > minutely_tick

終端僅響應:

[Function: bound ]

為什么我沒有從Cloud Function中獲取console.logs,就像通常在生產環境中運行該函數時那樣?

您在模擬器中鍵入的命令不正確。 您正在執行的操作是有效地告訴仿真器(這只是一個節點REPL)打印標識符minutely_tick的內容,而這僅僅是一個函數的名稱。 要執行該功能,您必須實際使用它將接收的參數來調用它。

根據文檔

對於PubSub函數,將消息有效負載插入Buffer實例,並添加可選的數據屬性,如下所示:

 // invokes a function with the JSON message { hello: 'world' } and attributes { foo: 'bar' } myPubsubFunction({data: new Buffer('{"hello":"world"}'), attributes: {foo: 'bar'}}) 

對於您的情況,您將使用名為minutely_tick的函數,並將要測試的有效負載傳遞給該函數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM