(experimental)
This package provides a zap logger that forwards entries to the Google Stackdriver Logging service as structured payloads.
Outside of Google Compute Engine, just add the environment variable GOOGLE_APPLICATION_CREDENTIALS
with a path to a JSON credential file. For more info on this approach, see the docs.
import "github.com/jonstaryuk/gcloudzap"
log, err := gcloudzap.NewDevelopment("your-project-id", "your-log-id")
if err != nil {
panic(err)
}
log.Sugar().
With("simple", true).
With("foo", "bar").
Info("This will get written to both stderr and Stackdriver Logging.")
import (
"go.uber.org/zap"
"cloud.google.com/go/logging"
"github.com/jonstaryuk/gcloudzap"
)
// Configure the pieces
client, err := logging.NewClient(...)
cfg := zap.Config{...}
// Create a logger
log, err := gcloudzap.New(cfg, client, "your-log-id", zap.Option(), ...)
import (
"go.uber.org/zap/zapcore"
"cloud.google.com/go/logging"
"github.com/jonstaryuk/gcloudzap"
)
// Configure the pieces
client, err := logging.NewClient(...)
baseCore := zapcore.NewCore(...)
// Create a core
core := gcloudzap.Tee(baseCore, client, "your-log-id")