A newer version of this documentation is available.

View Latest

Collecting Information and Logging in the Go SDK with Couchbase Server

The Go SDK offers simple logging of library internals to help debug issues. Logging may be configured on a global library-level basis. Note that the logging API is subject to change.

You can configure logging using the gocb.SetLogger, which accepts an implementation of gocb.Logger. The SDK comes with two built-in Logger implementations, which can be instantiated using the following methods:

  • gocb.DefaultStdioLogger() returns a logger that logs errors and warnings. This is fairly non-disruptive and does not produce a lot of output.

  • gocb.VerboseStdioLogger() returns a logger that logs more detailed tracing information. This logger should only be used when trying to diagnose an issue.

import (
        "github.com/couchbase/gocb"
)

func main() {
        gocb.SetLogger(gocb.DefaultStdioLogger())

        // Use the gocb library.
}

It is also possible to provide other logger implementations to gocb.SetLogger. Implementations must satisify the gocb.Logger interface.

  type Logger interface {
	// Outputs logging information:
	// level is the verbosity level
	// offset is the position within the calling stack from which the message
	// originated. This is useful for contextual loggers which retrieve file/line
	// information.
	Log(level LogLevel, offset int, format string, v ...interface{}) error
}

The gocb.DefaultStdioLogger() and gocb.VerboseStdioLogger() wrap their gocbcore counterparts to provide a stable interface. The gocb versions should be used.