zap

package module
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: MIT Imports: 6 Imported by: 1

README

slog.Logger adapter for zap

Go Reference

This package implements a wrapper around a *zap.Logger so it can be used as a slog.Logger.

See also

Documentation

Overview

Package zap provides a slog.Logger adaptor using a go.uber.org/zap Logger as backend

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(cfg *zap.Config) slog.Logger

New creates a slog.Logger adaptor using a zap as backend. If none was passed it will create an opiniated new one.

func NewDefaultConfig added in v0.3.7

func NewDefaultConfig() *zap.Config

NewDefaultConfig creates a new zap.Config logging to the console.

Types

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger is an adaptor using go.uber.org/zap as slog.Logger

func NewNoop

func NewNoop() *Logger

NewNoop returns a no-op Logger. It never writes out logs or internal errors

func (*Logger) Debug

func (zpl *Logger) Debug() slog.Logger

Debug returns a new logger set to add entries as level Debug

func (*Logger) Enabled

func (zpl *Logger) Enabled() bool

Enabled tells this logger is enabled

func (*Logger) Error

func (zpl *Logger) Error() slog.Logger

Error returns a new logger set to add entries as level Error

func (*Logger) Fatal

func (zpl *Logger) Fatal() slog.Logger

Fatal returns a new logger set to add entries as level Fatal

func (*Logger) Info

func (zpl *Logger) Info() slog.Logger

Info returns a new logger set to add entries as level Info

func (*Logger) NewWithCallback

func (zpl *Logger) NewWithCallback(fn func(lv zapcore.Entry) error) *Logger

NewWithCallback creates a new zap logger using a callback to modify it.

func (*Logger) Panic

func (zpl *Logger) Panic() slog.Logger

Panic returns a new logger set to add entries as level Panic

func (*Logger) Print

func (zpl *Logger) Print(args ...any)

Print adds a log entry with arguments handled in the manner of fmt.Print

func (*Logger) Printf

func (zpl *Logger) Printf(format string, args ...any)

Printf adds a log entry with arguments handled in the manner of fmt.Printf

func (*Logger) Println

func (zpl *Logger) Println(args ...any)

Println adds a log entry with arguments handled in the manner of fmt.Println

func (*Logger) Unwrap added in v0.3.7

func (zpl *Logger) Unwrap() (*zap.Logger, *zap.Config)

Unwrap returns the underlying zap logger

func (*Logger) Warn

func (zpl *Logger) Warn() slog.Logger

Warn returns a new logger set to add entries as level Warn

func (*Logger) WithEnabled

func (zpl *Logger) WithEnabled() (slog.Logger, bool)

WithEnabled passes the logger and if it's enabled

func (*Logger) WithField

func (zpl *Logger) WithField(label string, value any) slog.Logger

WithField returns a new logger with a field attached

func (*Logger) WithFields

func (zpl *Logger) WithFields(fields map[string]any) slog.Logger

WithFields returns a new logger with a set of fields attached

func (*Logger) WithLevel

func (zpl *Logger) WithLevel(level slog.LogLevel) slog.Logger

WithLevel returns a new logger set to add entries to the specified level

func (*Logger) WithStack

func (zpl *Logger) WithStack(skip int) slog.Logger

WithStack attaches a call stack to a new logger

Jump to

Keyboard shortcuts

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