Rewrite logging client instantiation

This commit is contained in:
olemorud
2022-12-08 00:35:24 +01:00
parent 127a406733
commit 3189c5d145

View File

@@ -42,20 +42,13 @@ func contains(haystack []string, needle string) bool {
// Coffee() replies to mattermost webhooks with the correct token value
func Coffee(writer http.ResponseWriter, request *http.Request) {
project_id := os.Getenv("PROJECT_ID")
if project_id == "" {
log.Fatal("Environment variable PROJECT_ID is empty")
}
// Create cloud logging client
ctx := context.Background()
client, err := logging.NewClient(ctx, project_id)
logger := client.Logger("Coffee-log")
var stdlog *log.Logger
if err != nil {
defer client.Close()
logger := client.Logger("Coffee-log")
stdlog = logger.StandardLogger(logging.Debug)
} else {
log.Printf("Failed to create logging client: %v", err)