Giter Club home page Giter Club logo

gcloudzap's Introduction

⚡ gcloudzap GoDoc

(experimental)

Formerly https://github.com/jonstaryuk/gcloudzap

This package provides a zap logger that forwards entries to the Google Stackdriver Logging service as structured payloads.

Quickstart

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.

Option 1: Less configuration

import "github.com/dhduvall/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.")

Option 2: More flexibility

import (
    "go.uber.org/zap"
    "cloud.google.com/go/logging"
    "github.com/dhduvall/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(), ...)

Option 3: Most flexibility

import (
    "go.uber.org/zap/zapcore"
    "cloud.google.com/go/logging"
    "github.com/dhduvall/gcloudzap"
)

// Configure the pieces
client, err := logging.NewClient(...)
baseCore := zapcore.NewCore(...)

// Create a core
core := gcloudzap.Tee(baseCore, client, "your-log-id")

gcloudzap's People

Contributors

dhduvall avatar jonstaryuk avatar

Stargazers

 avatar

Watchers

 avatar  avatar

gcloudzap's Issues

Logger crashes with zap.Time argument

The logger adapter crashes if logger.Info/Error etc is given a zap.Time argument.

panic: interface conversion: interface {} is *time.Location, not time.Time

goroutine 1 [running]:
github.com/dhduvall/gcloudzap.clone(0x0, 0xc0000df180, 0x1, 0x1, 0x1)
	/Users/niko/go/pkg/mod/github.com/dhduvall/[email protected]/gcloudzap.go:252 +0x1201
github.com/dhduvall/gcloudzap.(*Core).Write(0xc00026af60, 0x0, 0xbf637287b5822e60, 0x44cffa, 0x1a900e0, 0x0, 0x0, 0x1601f74, 0x8, 0x0, ...)
	/Users/niko/go/pkg/mod/github.com/dhduvall/[email protected]/gcloudzap.go:174 +0xb9
go.uber.org/zap/zapcore.(*CheckedEntry).Write(0xc0002a80b0, 0xc0000df180, 0x1, 0x1)

Minimal working example (set GOOGLE_APPLICATION_CREDENTIALS before running):

package main

import (
	"time"

	"github.com/dhduvall/gcloudzap"
	"go.uber.org/zap"
)

func main() {
	logger, err := gcloudzap.NewProduction("test-project", "test-logger")
	if err != nil {
		panic(err)
	}
	logger.Info("Time now", zap.Time("ts", time.Now()))
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.