TL;DR;
Does anyone know if it's possible to use console.log
in a Firebase/Google Cloud Function to log entries to Stack Driver using the jsonPayload
property so my logs are searchable (currently anything I pass to console.log gets stringified into textPayload
).
I have a multi-module project with some code running on Firebase Cloud Functions, and some running in other environments like Google Compute Engine. Simplifying things a little, I essentially have a 'core' module, and then I deploy the 'cloud-functions' module to Cloud Functions, 'backend-service' to GCE, which all depend on 'core' etc.
I'm using bunyan for logging throughout my 'core' module, and when deployed to GCE the logger is configured using '@google-cloud/logging-bunyan' so my logs go to Stack Driver.
Aside: Using this configuration in Google Cloud Functions is causing issues with Error: Endpoint read failed
which I think is due to functions not going cold and trying to reuse dead connections, but I'm not 100% sure what the real cause is.
So now I'm trying to log using console.log(arg)
where arg
is an object, not a string. I want this object to appear in Stack Driver under the jsonPayload
but it's being stringified and put into the textPayload
field.
Error: Endpoint read failed
is happening, but that would probably take just as long as following their documentation on usingconsole.log
as described here cloud.google.com/functions/docs/monitoring/logging – Brawl