Search code examples
google-apps-scriptloggingstackdrivergoogle-cloud-stackdriver

Stackdriver logging - Why is not my payload showing correctly in Runtime V8


I add a simple log message and I see the log in Stackdriver.
But the payload is not splited to separate values.
The problem is that Payload is shown as one big string with message and payload.
I need a list of values so I can Query for ex isValid or content.

How can I get the payload to a list of values inside Stackdriver logging?

https://developers.google.com/apps-script/guides/logging#using_cloud_logging

// Log a JSON object at a DEBUG level. The log is labeled
  // with the message string in the log viewer, and the JSON content
  // is displayed in the expanded log structure under "jsonPayload".
  var parameters = {
      isValid: true,
      content: 'some string',
      timestamp: new Date()
  };
  console.log({message: 'Function Input', initialData: parameters});

enter image description here

Update
If downgrade project to ["runtimeVersion": "DEPRECATED_ES5"] payload work correct.
If I run project in new "Runtime Chrome V8" the payload is NOT working.


Solution

  • I had the same situation. In such case, I use Logger.log instead of console.log. So please modify as follows and test it again.

    From:

    console.log({message: 'Function Input', initialData: parameters});
    

    To:

    Logger.log({message: 'Function Input', initialData: parameters});
    

    Result:

    When Logger.log is used for the value, the following result is obtained. In this case, even when V8 runtime is enabled, the object is parsed at the Stackdriver.

    enter image description here

    Note:

    Reference: