github.com/zchee/zap-cloudlogging@v0.0.0-20220819025602-19b026d3900e/service.go (about)

     1  // Copyright 2022 The zap-cloudlogging Authors
     2  // SPDX-License-Identifier: BSD-3-Clause
     3  
     4  package zapcloudlogging
     5  
     6  import (
     7  	"go.uber.org/zap"
     8  	"go.uber.org/zap/zapcore"
     9  )
    10  
    11  const (
    12  	serviceContextKey = "serviceContext"
    13  )
    14  
    15  // ServiceContext adds the service information adding the log line.
    16  // It is a required field if an error needs to be reported.
    17  //
    18  // ServiceContext: https://cloud.google.com/error-reporting/reference/rest/v1beta1/ServiceContext
    19  func ServiceContext(name string) zap.Field {
    20  	return zap.Object(serviceContextKey, zapcore.ObjectMarshalerFunc(func(enc zapcore.ObjectEncoder) error {
    21  		enc.AddString("service", name)
    22  
    23  		return nil
    24  	}))
    25  }