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:
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!
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With