Google Cloud Logging
This forwarder is used to send a log record to Google Cloud Logging.
Data Model
note
- The credentials are NOT encrypted in the database.
disable_tlsanddisable_authare meant to target a local emulator or a test server, they should not be used against the Google Cloud Logging API.
Behavior
opts := []option.ClientOption{
option.WithEndpoint(host + ":" + strconv.Itoa(port)),
}
if len(authJSON) > 0 {
opts = append(opts, option.WithAuthCredentialsJSON(
option.ServiceAccount,
[]byte(authJSON),
))
}
if disableAuth {
opts = append(opts, option.WithoutAuthentication())
}
if disableTLS {
opts = append(opts, option.WithGRPCDialOption(
grpc.WithTransportCredentials(insecure.NewCredentials()),
))
}
client, err := logging.NewClient(ctx, projectID, opts...)
// ...
logger := client.Logger(logID)
payload, err := json.Marshal(logRecord.Fields)
// ...
err = logger.LogSync(ctx, logging.Entry{
Timestamp: logRecord.Timestamp,
Payload: json.RawMessage(payload),
})
// ...