Structured logging in stackdriver from gcloud function

Hello! First post in this forum, and new to golang.

I’ve developed a simple function in golang and implemented it in a google cloud function. It works fine.
When I print to the standard output, I see a line in the logs viewer in the stackdriver.

So, I decided to log a json with all the execution (parameters received, data, etc) and print to the standard output a simple json containing all the relevant information.
When I print that json to the standard output in my local environment, works fine. But when I print the same json in the cloud function, the stackdriver loggin logs a strange json.

This is my json, printed to the standard output in my console:
“{“ReceivedData”:[{“Key”:“SystemUser”,“Value”:“xxxxx”},“Key”:“password”,“Value”:“sdasdasd”},{“Key”:“Dominio”,“Value”:“abc123”},{“Key”:“NroSerie”,“Value”:“12345”},(…)”

When I print the same json in the google cloud function, what I see in the log viewer is a different json, with lot of strange fields:
“{“fields”:{“ReceivedData”:{“Kind”:{“ListValue”:{“values”:[{“Kind”:{“StructValue”:{“fields”:{“Key”:{“Kind”:{“StringValue”:“Velocidad”}},“Value”:{“Kind”:{(…)”

this is part of my code. Any help is welcome!!

type Pair struct {
Key string json:key
Value string json:value
}

type DataToLog struct {
ReceivedData []Pair json:DataFromGet
ServerResponse string json:ServerResponse
ServerData string json:ServerData
RemoteIP string json:RemoteIP
DataToQMT DataToSend
}

func RequestHandler(w http.ResponseWriter, r *http.Request) {

var log DataToLog

(.. code that fills the struct...)

byteArrayLog, _ := json.Marshal(log)
fmt.Println(string(byteArrayLog))

}

Thanks

Hey, i encountered the same issue. Did you find a solution?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.