Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Functions logging objects takes up a lot of space

We have our firebase function console.log() an object near the end of the execution.

In the past it always clumped the entire object into one single dropdown in the Firebase Functions Log interface but now it seems to put each key of the object in a separate line making it not only take up more space but quite unreadable.

This seems to happen mostly when objects are stringified like:

console.log(JSON.stringify({key1: 'val1', key2: 'val2'}))

Below is an example of an error object being logged:

enter image description here

How can this madness be put into a single dropdown again?

We are using:

"firebase-admin": "^8.6.1",
"firebase-functions": "^3.3.0",

Thank you!

like image 878
T Mack Avatar asked Nov 28 '19 02:11

T Mack


Video Answer


2 Answers

If you have an object to log, I recommend just pass it directly to console.log(). JSON.stringify() might be adding carriage returns, which could be interpreted as multiple lines to log.

console.log({key1: 'val1', key2: 'val2'})

Just make sure that the object doesn't contain references to other very complex objects (especially self-referential objects), otherwise it could cause problems with evaluating the final string at runtime.

like image 68
Doug Stevenson Avatar answered Oct 15 '22 02:10

Doug Stevenson


Neither console.log(data) nor console.log(JSON.stringify(data)) worked for me. Using the sdk logger worked for me:

import * as functions from 'firebase-functions';
functions.logger.log(data);

As described here: https://firebase.google.com/docs/functions/writing-and-viewing-logs#logger-sdk

like image 24
user1689987 Avatar answered Oct 15 '22 00:10

user1689987