Skip to content

wayneashleyberry/zaperations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Package zaperations provides a Google Cloud Operations (formerly Stackdriver) compatible config for the excellent uber-go/zap logger.

Go Reference Go Go Report Card

Example

This example is using unreleased functionality from go tip that is set to be released in 1.18.

package main

import (
	"runtime/debug"

	"github.com/wayneashleyberry/zaperations/pkg/logger"
	"github.com/wayneashleyberry/zaperations/pkg/meta"
	"go.uber.org/zap"
)

func main() {
	log, err := logger.NewProduction()
	if err != nil {
		panic(err)
	}

	info, ok := debug.ReadBuildInfo()
	if !ok {
		panic("could not read build info")
	}

	var version string

	for _, setting := range info.Settings {
		if setting.Key == "gitrevision" {
			version = setting.Value
		}
	}

	log = log.With(zap.Object("serviceContext", meta.ServiceContext{
		Service: "logger-demo",
		Version: version,
	}))

	log.Info("Hello, World!")
}

About

Package zaperations provides a Google Cloud operations suite (formerly Stackdriver) compatible config for the uber-go/zap logger.

Topics

Resources

License

Stars

Watchers

Forks

Languages