Skip to content

trim21/zerolog-as-slog-handler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

use zerolog as slog handler

package main

import (
	"log/slog"
	"os"

	"github.com/rs/zerolog"

	zerologassloghandler "github.com/trim21/zerolog-as-slog-handler"
)

func main() {
	h := zerologassloghandler.FromZerolog(zerolog.New(os.Stderr))

	l := slog.New(h)

	// {"level":"info","hello":"world","time":"2024-08-13T04:33:58+08:00","message":"1"}
	l.With("hello", "world").Info("1")

	// {"level":"info","j":{"hello":"world"},"time":"2024-08-13T04:33:58+08:00","message":"2"}
	l.WithGroup("j").With("hello", "world").Info("2")

	// {"level":"info","time":"2024-08-13T04:33:58+08:00","message":"3"}
	l.Info("3")
}

This is a immature implement for using zerolog as slog.Handler. it pass most of slogtest except multi-With (nested group, l.With("a", "b").WithGroup("G").With("c", "d").WithGroup("H").Info("msg", "e", "f")

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages