zerozap

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: MPL-2.0 Imports: 8 Imported by: 2

README

zerozap

An implementation of zapcore.Core to feed all data to a zerolog logger.

Basic example

package main

import (
	"os"

	"github.com/rs/zerolog"
	"go.mau.fi/zerozap"
	"go.uber.org/zap"
)

func main() {
	mainLog := zerolog.New(os.Stdout)
	zapLogger := zap.New(zerozap.New(mainLog))
	zapLogger.Info("Hello, world!")
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// CopyTime controls whether the time field from zap is copied to zerolog.
	// The time will be placed in [zerolog.TimestampFieldName].
	CopyTime = true
	// CopyStack controls whether the stack field from zap (if present) is copied to zerolog.
	// The stack string will be placed in [zerolog.ErrorStackFieldName].
	CopyStack = true
	// CopyCaller controls whether the caller field from zap (if present) is copied to zerolog.
	// The caller info will be placed in [zerolog.CallerFieldName] after being marshaled using [zerolog.CallerMarshalFunc].
	CopyCaller = true
)

Functions

func New

func New(log zerolog.Logger) zapcore.Core

New creates a new zapcore.Core using the given zerolog instance.

Example
package main

import (
	"os"

	"github.com/rs/zerolog"
	"go.uber.org/zap"

	"go.mau.fi/zerozap"
)

func main() {
	zlog := zerolog.New(os.Stdout)

	zaplog := zap.New(zerozap.New(zlog))
	zaplog.Info("Hello, world!")
}
Output:

{"level":"info","message":"Hello, world!"}

func Option

func Option(log zerolog.Logger) zap.Option

Option creates a zap.Option that will replace the core of an existing zap logger with a ZeroZap core.

Example
package main

import (
	"os"

	"github.com/rs/zerolog"
	"go.uber.org/zap"

	"go.mau.fi/zerozap"
)

func main() {
	zlog := zerolog.New(os.Stdout)

	zaplog := zap.NewNop()
	zaplog.Info("This is not logged")

	zaplog = zaplog.WithOptions(zerozap.Option(zlog))
	zaplog.Info("This is logged")
}
Output:

{"level":"info","message":"This is logged"}

Types

This section is empty.

Jump to

Keyboard shortcuts

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