A newer version of this documentation is available.

View Latest

Collecting Information & Logging

    Logging with gocb.Logger & using other implementations.

    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 (
    func main() {
            // 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.

    Log Redaction

    Redacting logs is a two-stage process. If you want to redact client logs (for example before handing them off to the Couchbase Support team) you first need to enable log redaction in your application.


    Different redaction levels are supported — please see the RedactionLevel enum description for more information.

    Note that you need to run this command before any of the SDK code is initialized so all of the logs are captured properly. Once the SDK writes the logs with the tags to a file, you can then use the cblogredaction tool to obfuscate the log.