Search code examples
node.jsfirebasegoogle-cloud-functionsstackdrivergoogle-cloud-stackdriver

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!


Solution

  • 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.