Firebase functions not logging "console.log()" statements

You have to return the promise returned by the asynchronous get() method, see the doc here which indicates that "To return data after an asynchronous operation, return a promise. The data returned by the promise is sent back to the client."

So the following should work:

exports.purchaseItem = functions.https.onCall((data, context) => {
  console.log('data:')
  console.log(data)
  let lbcCustomerStripeToken = data.lbcCustomerStripeToken
  let lbcStoreId = data.lbcStoreId
  let amount = data.amount
  console.log('lbcCustomerStripeToken:')
  console.log(lbcCustomerStripeToken)
  console.log('lbcStoreId:')
  console.log(lbcStoreId)
  console.log('amount:')
  console.log(amount)

  let lbcFee = Math.round(amount * 0.02)

  return db.collection('stores').doc(lbcStoreId).get().then(lbcStore => {
    if (!lbcStore.exists) {
      console.log('No such product!');
    } else {
      console.log('Document data:', product.data());
    }
    console.log('storeInfo:')
    console.log(lbcStore.data())
    return {message: 'Success'}
  })    
  .catch((error) => {
    // To be adapted here, see https://firebase.google.com/docs/functions/callable#handle_errors
    console.log(error);
  });
};

Also, note that you should adapt your code for the error handling part, see https://firebase.google.com/docs/functions/callable#handle_errors.

Finally, be sure that your db constant is defined with admin.firestore();.


You can see the data that printed via console.log() in the specific function's Log tab in the Firebase console:

https://console.firebase.google.com/u/0/project/<project-name>/functions/logs

*Change <project-name> to yours (without < >).

*You may need to select specific function/log level to see the log in live.


You can also use view logs as it said in the documentation:

https://firebase.google.com/docs/functions/writing-and-viewing-logs#viewing_logs

To view logs with the firebase tool

firebase functions:log

To view logs for a specific function

firebase functions:log --only <FUNCTION_NAME>