tomMoulard / zap-slog

zap: slog core

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

zap: slog handler

A slog Core for zap library.

Install

go get -u github.com/tommoulard/zap-slog

Usage

GoDoc: https://pkg.go.dev/github.com/tommoulard/zap-slog

Example

package main

import (
	"log/slog"

	zapslog "github.com/tommoulard/zap-slog"
	"go.uber.org/zap"
)

func main() {
	slogger := slog.Default()
	logger, _ := zap.NewProduction(zapslog.WrapCore(slogger))
	logger = logger.Named("example")
	logger.Info("hello world")
}

Benchmarks

Here are a few benchmarks comparing the performance of the zap-slog wrapper against the zap library.

Both benchmarks are run with a logger that discards all logs.

$ go test ./... -bench=.
goos: linux
goarch: amd64
pkg: github.com/tommoulard/zap-slog
cpu: Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
BenchmarkWrapCore-12    	   677972	          1570 ns/op
BenchmarkZap-12         	217827159	         5.336 ns/op
PASS
ok  	github.com/tommoulard/zap-slog	2.810s

About

zap: slog core

License:MIT License


Languages

Language:HTML 53.3%Language:Go 37.2%Language:Makefile 9.5%