zbark

package
v0.0.0-...-11e8d8f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2016 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package zbark provides a wrapper to make zap.Loggers compatible with the bark.Logger interface and a wrapper to make bark.Loggers compatible with zap.Logger interface.

This package is only of interest to users of github.com/uber-common/bark.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Barkify

func Barkify(l zap.Logger) bark.Logger

Barkify wraps zap's JSON logger to make it compatible with the bark.Logger interface.

Example
package main

import (
	"github.com/uber-go/zap"
	"github.com/uber-go/zap/zbark"
)

func main() {
	zapLogger := zap.New(zap.NewJSONEncoder(
		zap.NoTime(), // discard timestamps in tests
	))

	// Wrap our structured logger to mimic bark.Logger.
	logger := zbark.Barkify(zapLogger)

	// The wrapped logger has bark's usual fluent API.
	logger.WithField("errors", 0).Infof("%v accepts arbitrary types.", "Bark")

}
Output:

{"level":"info","msg":"Bark accepts arbitrary types.","errors":0}

func Debarkify

func Debarkify(bl bark.Logger, lvl zap.Level) zap.Logger

Debarkify wraps bark.Logger to make it compatible with zap's JSON logger

Example
package main

import (
	"os"

	"github.com/uber-go/zap"
	"github.com/uber-go/zap/zbark"

	"github.com/Sirupsen/logrus"
	"github.com/uber-common/bark"
)

func main() {
	logrusLogger := logrus.New()
	logrusLogger.Out = os.Stdout
	logrusLogger.Formatter = &logrus.JSONFormatter{
		TimestampFormat: "lies",
	}
	barkLogger := bark.NewLoggerFromLogrus(logrusLogger).WithField("errors", 0)
	logger := zbark.Debarkify(barkLogger, zap.DebugLevel)

	// The wrapped logger has zap's actually fluent API.
	logger.Info("Zap accepts", zap.String("typed", "fields"))

}
Output:

{"errors":0,"level":"info","msg":"Zap accepts","time":"lies","typed":"fields"}

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL