Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include a minimal working example as quickstart guide #20

Closed
mark-kubacki opened this issue Dec 29, 2018 · 1 comment
Closed

include a minimal working example as quickstart guide #20

mark-kubacki opened this issue Dec 29, 2018 · 1 comment

Comments

@mark-kubacki
Copy link

Hey, thanks for zapdriver!

I am struggling to fit it in my toy project, and feel that a minimal working example as quickstart guide could be of benefit here.

For example, going with the very last section of the current README file, this does not yield the promised everything just works ™:

//name:above.go

package main

import (
        "fmt"

        "go.uber.org/zap"
        "go.uber.org/zap/zapcore"
        "github.com/blendle/zapdriver"
)

func main() {
        var log *zap.Logger
        {
                config := zap.NewDevelopmentConfig()
                config.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
                log, _ = config.Build(zapdriver.WrapCore()) // ←
                // log = log.Named("hello-world")
                defer log.Sync()
        }

        log.Info("stub start")
        fmt.Println("Hello world!")
        log.Info("stub end")
}
$ export GOOGLE_APPLICATION_CREDENTIALS="….json"
$ go run above.go

… nothing shows up in Stackdriver,

@JeanMertz
Copy link
Contributor

this does not yield the promised everything just works

Fair point. We're using this library on top of GKE (Kubernetes), which already streams all the logs of all the containers to Stackdriver. This library only structures the logs in such away that they match the expected log format of Stackdriver.

We use a small wrapper library around this library to make it easy to initialise the Zap logger itself. See: https://github.com/blendle/go-logger.

From looking at your snippet above, first of all, you should see logs appear in stdout when you run go run above.go. The format of those log lines should match what Stackdriver expects. What you are missing is the component that sends those logs to the correct Stackdriver API. That is not something that this library provides, it is only a wrapper around Zap to format the logs to Stackdriver's specification.

I'd welcome any updates to the README to link out to some helpful documentation on how to actually hook your application into Stackdriver, but I don't think actually writing those steps out in the README is within the scope of this library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants