logwise

package module
v0.0.0-...-13ff2ac Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: MIT Imports: 17 Imported by: 0

README

LogWise

Installation

go get -u github.com/gowool/logwise

License

Distributed under MIT License, please see license file within the code for more details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandlerSyncer

func NewHandlerSyncer(syncer zapcore.WriteSyncer, handler slog.Handler) slog.Handler

func NewStdLog

func NewStdLog(base *slog.Logger, prefix string) *log.Logger

func NewZap

func NewZap(log *slog.Logger) *zap.Logger

func NewZapCore

func NewZapCore(log *slog.Logger) zapcore.Core

func ToAttrs

func ToAttrs(data map[string]any) []slog.Attr

func ToLeveler

func ToLeveler(level string) slog.Leveler

Types

type Config

type Config struct {
	// When AddSource is true, the handler adds a ("source", "file:line")
	// attribute to the output indicating the source code position of the log
	// statement. AddSource is false by default to skip the cost of computing
	// this information.
	AddSource bool `cfg:"add_source" mapstructure:"add_source" json:"add_source,omitempty" yaml:"add_source,omitempty"`

	// Level is the minimum enabled logging level.
	Level string `cfg:"level"  mapstructure:"level" json:"level,omitempty" yaml:"level,omitempty"`

	// Encoding sets the logger's encoding. Init values are "json", "text" and "console"
	Encoding string `cfg:"encoding" mapstructure:"encoding" json:"encoding,omitempty" yaml:"encoding,omitempty"`

	// Output is a list of URLs or file paths to write logging output to.
	// See zap.Open for details.
	OutputPaths []string `cfg:"output_paths" mapstructure:"output_paths" json:"output_paths,omitempty" yaml:"output_paths,omitempty"`

	Attributes map[string]any `cfg:"attributes" mapstructure:"attributes" json:"attributes,omitempty" yaml:"attributes,omitempty"`
}

func (*Config) Logger

func (cfg *Config) Logger(attrs ...slog.Attr) (*slog.Logger, error)

func (*Config) OpenSinks

func (cfg *Config) OpenSinks() (zapcore.WriteSyncer, error)

func (*Config) Opts

func (cfg *Config) Opts() *HandlerOptions

type ConsoleHandler

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

func NewConsoleHandler

func NewConsoleHandler(w io.Writer, opts *slog.HandlerOptions, attrs ...slog.Attr) *ConsoleHandler

func (*ConsoleHandler) Enabled

func (h *ConsoleHandler) Enabled(_ context.Context, l slog.Level) bool

func (*ConsoleHandler) Handle

func (h *ConsoleHandler) Handle(_ context.Context, r slog.Record) error

func (*ConsoleHandler) WithAttrs

func (h *ConsoleHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*ConsoleHandler) WithGroup

func (h *ConsoleHandler) WithGroup(name string) slog.Handler

type HandlerOptions

type HandlerOptions struct {
	*slog.HandlerOptions
}

func (HandlerOptions) NewHandler

func (opts HandlerOptions) NewHandler(w io.Writer, encoding string) slog.Handler

type HandlerSyncer

type HandlerSyncer interface {
	Sync() error
}

type StdLogAdapter

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

StdLogAdapter can be passed to the http.Server or any place which required standard logger to redirect output to the logger plugin

func NewStdAdapter

func NewStdAdapter(log *slog.Logger) *StdLogAdapter

NewStdAdapter constructs StdLogAdapter

func (*StdLogAdapter) Write

func (s *StdLogAdapter) Write(p []byte) (n int, err error)

Write io.Writer interface implementation

type ZapCore

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

func (*ZapCore) Check

func (*ZapCore) Enabled

func (c *ZapCore) Enabled(lvl zapcore.Level) bool

func (*ZapCore) Sync

func (c *ZapCore) Sync() error

func (*ZapCore) With

func (c *ZapCore) With(fields []zapcore.Field) zapcore.Core

func (*ZapCore) Write

func (c *ZapCore) Write(ent zapcore.Entry, fields []zapcore.Field) error

Jump to

Keyboard shortcuts

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