zaplog

package
v0.0.0-...-fe3b528 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package zaplog provides a constructor for zap.Logger with sensible defaults.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(w io.Writer) *zap.Logger

New returns a new zap.Logger that writes to w.

func Tee

func Tee(log *zap.Logger, core zapcore.Core) *zap.Logger

Tee returns log’s clone that duplicates log entries into another core.

Example
package main

import (
	"io"
	"os"

	"go.uber.org/zap"
	"go.uber.org/zap/zapcore"

	"github.com/pact-im/go-pkg/zaplog"
)

func main() {
	lg := zaplog.Tee(zaplog.New(io.Discard).With(
		// Note that Tee does carry existing context to the target
		// core since it’s attached to the current core only.
		zap.String("ignored", "oops"),
	), zapcore.NewCore(
		zapcore.NewConsoleEncoder(zapcore.EncoderConfig{
			MessageKey:       "msg",
			LevelKey:         "level",
			EncodeLevel:      zapcore.LowercaseLevelEncoder,
			ConsoleSeparator: ": ",
		}),
		zapcore.AddSync(os.Stdout),
		zap.DebugLevel,
	)).With(zap.String("shark", "gawr gura"))
	lg.Debug("cheeki breeki")
}
Output:

debug: cheeki breeki: {"shark": "gawr gura"}

Types

This section is empty.

Jump to

Keyboard shortcuts

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