Skip to content
/ logz Public

Package logz provides common logging interfaces for package library, allows users provide their logging implementation..

License

Notifications You must be signed in to change notification settings

ezpkg/logz

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gopherz

ezpkg.io/logz

PkgGoDev GitHub License version

Package logz provides common interfaces and utilities for working with other log packages, including log/slog and zap. It's useful for package library to provide a common interface for logging, so that the user can choose the logging package they want to use.

Installation

go get -u ezpkg.io/logz@v0.2.2

Examples

package mypackage

import "log/slog"
import "os"
import "testing"
import "go.uber.org/zap"

import "ezpkg.io/errorz"
import "ezpkg.io/logz"

type SuperPower struct {
	logger logz.Logger
}

func NewSuperPower(logger logz.Logger) (*SuperPower, error) {
	sp := &SuperPower{logger: logger}
	sp.logger.Debugw("A new SuperPower is created! Better be prepared! 🔥")
	return sp, nil
}

func TestSuperPowerUsingSlog(t *testing.T) {
	opt := &slog.HandlerOptions{Level: slog.LevelDebug}
	handler := slog.NewTextHandler(os.Stderr, opt)
	stdLogger := slog.New(handler)

	sp, err := NewSuperPower(logz.FromLoggerI(stdLogger))
	assertSuperPower(sp, err)
}
func TestSuperPowerUsingZap(t *testing.T) {
	zapLogger := errorz.Must(zap.NewDevelopment()).Sugar()

	sp, err := NewSuperPower(logz.FromLoggerx(zapLogger))
	assertSuperPower(sp, err)
}

About ezpkg.io

As I work on various Go projects, I often find myself creating utility functions, extending existing packages, or developing packages to solve specific problems. Moving from one project to another, I usually have to copy or rewrite these solutions. So I created this repository to have all these utilities and packages in one place. Hopefully, you'll find them useful as well.

For more information, see the main repository.

Author

Oliver Nguyen  github

About

Package logz provides common logging interfaces for package library, allows users provide their logging implementation..

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages