logwise

package
v0.0.0-...-54d658b Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const PluginName = "log"

Variables

This section is empty.

Functions

func NewHandlerSyncer

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

func NewXHandlerWrapper

func NewXHandlerWrapper(inner slog.Handler) xslog.Handler

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 ChannelConfig

type ChannelConfig struct {
	// Dedicated channels per logger. By default logger allocated via named logger.
	Channels map[string]Config `mapstructure:"channels" json:"channels,omitempty" bson:"channels,omitempty"`
}

ChannelConfig configures loggers per channel.

func NewChannelConfig

func NewChannelConfig(cfg configwise.Configurer, key string) (c ChannelConfig, err error)

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 `mapstructure:"add_source" json:"add_source,omitempty" bson:"add_source,omitempty"`

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

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

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

	Attrs map[string]any `mapstructure:"attributes" json:"attrs,omitempty" bson:"attrs,omitempty"`
}

func NewConfig

func NewConfig(cfg configwise.Configurer, key string) (c Config, err error)

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 Log

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

func Load

func Load(cfg configwise.Configurer) (*Log, error)

func NewLogger

func NewLogger(cfg Config, channels ChannelConfig, attrs ...slog.Attr) *Log

func (*Log) NamedLogger

func (l *Log) NamedLogger(name string) *slog.Logger

func (*Log) NamedXLogger

func (l *Log) NamedXLogger(name string) *xslog.Logger

func (*Log) NamedZapLogger

func (l *Log) NamedZapLogger(name string) *zap.Logger

func (*Log) Sync

func (l *Log) Sync() (err error)

type Logger

type Logger interface {
	NamedLogger(name string) *slog.Logger
	NamedXLogger(name string) *xslog.Logger
	NamedZapLogger(name string) *zap.Logger
}

type Plugin

type Plugin struct {
	Log Logger
}

func (*Plugin) Init

func (p *Plugin) Init() error

func (*Plugin) Logger

func (p *Plugin) Logger() Logger

func (*Plugin) Name

func (p *Plugin) Name() string

func (*Plugin) Provides

func (p *Plugin) Provides() []*dep.Out

func (*Plugin) Serve

func (p *Plugin) Serve() chan error

func (*Plugin) Stop

func (p *Plugin) Stop(context.Context) error

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