Firebase云端function无法正常logging

我正在创build一个社交应用程序,在这个应用程序中,朋友可以通过他们的地址簿find对方。 基本上,我有两个长长的电话号码列表,我想使用firebase-cloud-function来查找两个列表中的所有数字。

为此,我将用户的所有联系信息发布到Firebase实时数据库,并触发云function(.onWrite)。 云function获取所有刚刚发布的电话号码,然后检索我的数据库中所有经过validation的电话号码,然后需要交叉引用这两个列表以查找所有匹配的电话号码。

这是我的代码…

exports.crossReferenceContacts = functions.database.ref('/cross-ref-contacts/{userId}').onWrite(event => { //if it already existed then this function triggered beacuse we are calling set(null) and thus we dont want to proceed if (event.data.previous.exists()) { console.log("PREVIOUSLY EXISTED. RETURN NULL!!!"); return null; } const userId = event.params.userId; const userContacts = event.data.val(); var contactsOnPhone = []; var contactsVerifiedInDatabase =[]; var matchedContacts= []; for (var key in userContacts){ let contact = new Object(); contact.contactName = userContacts[key]; contact.number = key; contactsOnPhone.push(contact); }; var verifiedNumsRef = event.data.adminRef.root.child('verified-phone-numbers'); return verifiedNumsRef.once('value', function(snapshot) { const verifiedUsers = snapshot.val(); for (key in verifiedUsers){ const number = key const userInfo = verifiedUsers[key]; for (key in userInfo){ const uid = key; const username = userInfo[key]; var verifiedContact = new Object(); verifiedContact.name = username; verifiedContact.uid = uid; verifiedContact.number = number; contactsVerifiedInDatabase.push(verifiedContact); }; }; var verifiedNumbers = contactsVerifiedInDatabase.map(function(x){ return x.number; }); var contactNumbers = contactsOnPhone.map(function(x){ return x.number; }); //THIS LINE DOES NOT EVEN GET LOGGED UNLESS I COMMENT OUT THE FOR-LOOP BELOW, ONLY THEN DOES THIS LINE GETS LOGGED console.log('got ', verifiedNumbers.length, ' verified numbers along with', contactsVerifiedInDatabase.length, ' verfieid contacts. Also got', contactNumbers.length, ' phone numbers along with ', contactsOnPhone.length, ' phone contacts'); for (i = 0; i < contactNumbers.length; i++){ console.log("i = ", i); if (verifiedNumbers.includes(contactNumbers[i])) { console.log("GOT A MATCH WITH # ", contactNumbers[i]); } else { console.log("No mATCH FOR # ", contactNumbers[i]); }; }; return null; }); }); 

出于某种原因,当我运行firebase functions:log我的terminal,日志不完整。 这里是日志… 功能日志

为什么每次打印循环都不打印日志? 不应该打印i = 0到i = 409? 为什么总是从393开始? 而且该function正在完成状态“超时”,为什么呢?

firebase functions:log默认情况下, firebase functions:log只能输出一定数量的行。 看大约40左右。

您可以运行firebase help functions:log以获取命令行选项,告诉您:

 Usage: functions:log [options] read logs from deployed functions Options: -h, --help output usage information --only <function_names> only show logs of specified, comma-seperated functions (eg "funcA,funcB") -n, --lines <num_lines> specify number of log lines to fetch --open open logs page in web browser 

所以只需运行firebase functions:log -n 500即可获得500行。 他们没有说明它的第一个还是最后一个500,可能是最后一个。 但它够了。

函数帮助