Search code examples
logginggoogle-apps-scriptgoogle-cloud-platformgoogle-cloud-stackdriver

Changing the header of Stackdriver Logging logs in GCP


I am currently working on a GAS project with a lot of consol.log, but it's a project which will be deployed.

Is it possible to have a userName or a userMail in the header of a GCP Stakdriver Logging log entry, next to the date and time?

Here's the part I'm referring to:

1

Thank you for your answers.


Solution

  • You can't directly modify the header (it will always contain only the timestamp of the log), but you can add custom fields next to it.

    First, you have to include the fields you want to display (userName and userMail) in your entry log. You can include that in the jsonPayload field of the log entry (see the docs of Structured Logging). Once done, assuming that your fields are jsonPayload.userName and jsonPayload.userMail, you can do the following on Stackdriver Logging page in the Google Console :

    • click on View options (top-right corner, near Download logs)
    • choose Modify custom fields
    • add your fields as custom fields : jsonPayload.userName,jsonPayload.userMail

    Once refreshed, the web page should display your fields at the right of the timestamp.