Skip to content

Commit

Permalink
Fallback log to stdout for vulnfeeds (#1336)
Browse files Browse the repository at this point in the history
When GOOGLE_CLOUD_PROJECT env variable is not passed in, we fall back to
stdout logging rather than exiting.
  • Loading branch information
another-rex committed May 30, 2023
1 parent 9f32328 commit 262d8fd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions vulnfeeds/utility/logginghelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@ import (
// and also returns a cleanup function to be deferred
func CreateLoggerWrapper(name string) (LoggerWrapper, func()) {
projectId, ok := os.LookupEnv("GOOGLE_CLOUD_PROJECT")
var loggerOptions []logging.LoggerOption
if !ok {
log.Fatalf("GOOGLE_CLOUD_PROJECT not set")
log.Println("GOOGLE_CLOUD_PROJECT not set, routing logs to stdout")
loggerOptions = append(loggerOptions, logging.RedirectAsJSON(os.Stdout))
}
client, err := logging.NewClient(context.Background(), projectId)

if err != nil {
log.Fatalf("Failed to create client: %v", err)
}

wrapper := LoggerWrapper{
GCloudLogger: client.Logger(name),
GCloudLogger: client.Logger(name, loggerOptions...),
}

return wrapper, func() { client.Close() }
Expand Down

0 comments on commit 262d8fd

Please sign in to comment.