unilogger

package
v1.4.15-slog3 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

global logger is deprecated

Index

Constants

View Source
const KeyComponent = "component"

Variables

This section is empty.

Functions

func Debug

func Debug(msg string, args ...any)

func DebugContext

func DebugContext(ctx context.Context, msg string, args ...any)

func Debugf

func Debugf(format string, args ...any)

func Error

func Error(msg string, args ...any)

func ErrorContext

func ErrorContext(ctx context.Context, msg string, args ...any)

func Errorf

func Errorf(format string, args ...any)

func Fatal

func Fatal(msg string, args ...any)

func FatalContext

func FatalContext(ctx context.Context, msg string, args ...any)

func Fatalf

func Fatalf(format string, args ...any)

func Info

func Info(msg string, args ...any)

func InfoContext

func InfoContext(ctx context.Context, msg string, args ...any)

func Infof

func Infof(format string, args ...any)

func Log

func Log(ctx context.Context, level Level, msg string, args ...any)

func LogAttrs

func LogAttrs(ctx context.Context, level Level, msg string, attrs ...slog.Attr)

func Logf

func Logf(ctx context.Context, level Level, format string, args ...any)

func RawJSON

func RawJSON(key, text string) slog.Attr

func RawYAML

func RawYAML(key, text string) slog.Attr

func SetDefault

func SetDefault(l *Logger)

func SetDefaultLevel

func SetDefaultLevel(l Level)

func Trace

func Trace(msg string, args ...any)

func TraceContext

func TraceContext(ctx context.Context, msg string, args ...any)

func Tracef

func Tracef(format string, args ...any)

func Warn

func Warn(msg string, args ...any)

func WarnContext

func WarnContext(ctx context.Context, msg string, args ...any)

func Warnf

func Warnf(format string, args ...any)

Types

type AddSourceVar

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

func (*AddSourceVar) Set

func (v *AddSourceVar) Set(b bool)

func (*AddSourceVar) Source

func (v *AddSourceVar) Source() *bool

func (*AddSourceVar) String

func (v *AddSourceVar) String() string

type Level

type Level slog.Level
const (
	LevelTrace Level = -8
	LevelDebug Level = -4
	LevelInfo  Level = 0
	LevelWarn  Level = 4
	LevelError Level = 8
	LevelFatal Level = 12
)

func LogLevelFromStr

func LogLevelFromStr(rawLogLevel string) Level

func ParseLevel

func ParseLevel(rawLogLevel string) (Level, error)

func (Level) Level

func (l Level) Level() slog.Level

func (Level) String

func (l Level) String() string

type LogOutput

type LogOutput struct {
	Level      string `json:"level"`
	Name       string `json:"logger"`
	Message    string `json:"msg"`
	Source     string `json:"source"`
	FieldsJSON []byte `json:"-"`
	Stacktrace string `json:"stacktrace"`
	Time       string `json:"time"`
}

func (*LogOutput) MarshalJSON

func (a *LogOutput) MarshalJSON() ([]byte, error)

type Logger

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

func Default

func Default() *Logger

func NewLogger

func NewLogger(opts Options) *Logger

func NewNop

func NewNop() *Logger

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...any)

func (*Logger) Error

func (l *Logger) Error(msg string, args ...any)

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...any)

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, args ...any)

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, args ...any)

func (*Logger) GetLevel

func (l *Logger) GetLevel() Level

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...any)

func (*Logger) Logf

func (l *Logger) Logf(ctx context.Context, level Level, format string, args ...any)

func (*Logger) Named

func (l *Logger) Named(name string) *Logger

func (*Logger) SetLevel

func (l *Logger) SetLevel(level Level)

func (*Logger) SetOutput

func (l *Logger) SetOutput(w io.Writer)

func (*Logger) Trace

func (l *Logger) Trace(msg string, args ...any)

func (*Logger) Tracef

func (l *Logger) Tracef(format string, args ...any)

func (*Logger) Warnf

func (l *Logger) Warnf(format string, args ...any)

func (*Logger) With

func (l *Logger) With(args ...any) *Logger

func (*Logger) WithGroup

func (l *Logger) WithGroup(name string) *Logger

type Options

type Options struct {
	Level  slog.Level
	Output io.Writer

	TimeFunc func(t time.Time) time.Time
	// contains filtered or unexported fields
}

type Raw

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

func NewJSONRaw

func NewJSONRaw(text string) *Raw

made them public to use without slog.Attr

func NewYAMLRaw

func NewYAMLRaw(text string) *Raw

func (*Raw) LogValue

func (r *Raw) LogValue() slog.Value

type Render

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

func (*Render) JSONKeyValue

func (r *Render) JSONKeyValue(key, value string)

type SlogHandler

type SlogHandler struct {
	slog.Handler
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(out io.Writer, opts *slog.HandlerOptions, timeFn func(t time.Time) time.Time) *SlogHandler

func NewSlogHandler

func NewSlogHandler(handler slog.Handler) *SlogHandler

func (*SlogHandler) Handle

func (h *SlogHandler) Handle(ctx context.Context, r slog.Record) error

func (*SlogHandler) Named

func (h *SlogHandler) Named(name string) slog.Handler

func (*SlogHandler) WithAttrs

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

func (*SlogHandler) WithGroup

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

type WrappedLogger

type WrappedLogger struct {
	*slog.Logger
	// contains filtered or unexported fields
}

Extends default slog with new log levels

func NewSlogLogger

func NewSlogLogger(w io.Writer, opts *slog.HandlerOptions) *WrappedLogger

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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