I'm trying to get stackdriver logging working for a simple Go app running in Google Cloud Run (fully managed), but don't see stackdriver entries in CloudRun logs.
I've created simplest possible demo app based on "official" stackdriver golang example
Cloud Run docs states that no additional actions should be performed to write stackdriver logs
My service uses default service account
I'm using Go 1.13 to compile code (Dockerfile is copied from Cloud Run example "as-is")
I've tried to deploy it to different regions, with no success
When running container locally, using service account credentials, stackdriver log message does not appear in local terminal or stackdriver console
No matter what, on app start I see only "Before stackdriver logging"
followed by "After stackdriver logging"
with no other messages\errors in the middle
Here's part of logging code (use link above to get full source, Dockerfile and instructions to build and run the app):
import (
"context"
"log"
"os"
...
"cloud.google.com/go/compute/metadata"
"cloud.google.com/go/logging"
)
func main() {
loggingClient, err := stackdriverClient()
...
log.Println("Before stackdriver logging")
logger.StandardLogger(logging.Info).Println("Stackdriver log")
if err = logger.Flush(); err != nil {
log.Fatalf("Failed to flush client: %v", err)
}
if err = loggingClient.Close(); err != nil {
log.Fatalf("Failed to close client: %v", err)
}
log.Println("After stackdriver logging")
...
}
func stackdriverClient() (client *logging.Client, err error) {
var projectID string
if projectID, err = metadata.ProjectID(); err == nil {
client, err = logging.NewClient(context.Background(), projectID)
}
return
}
logger.StandardLogger
orlogging.Info
instead oflog.Println
, which is working? – Ramon Medeiros