qblog

package module
v0.14.6 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2024 License: MIT Imports: 17 Imported by: 17

README

[qb]log

Go Reference Go Report Card

import "git.fractalqb.de/fractalqb/qblog"

This is a logging library that brings together

to make a logging library that can coexists peacefully with other logging libraries.

Documentation

Overview

Example
log := New(DefaultConfig.Clone().SetWriter(os.Stdout))
log.Handler().(*SllmHandler).Clock = testClock
log.Info("bad login `from` at `time`", `from`, "10.0.0.1")
log.WithGroup("tests").
	With("time", testClock()).
	Info("bad login `from` at `time`", `from`, "10.0.0.1")
Output:

06-01 Tu 12:13:14+01 INFO  bad login `from:10.0.0.1` at `time:`
06-01 Tu 12:13:14+01 INFO  [tests] bad login `from:10.0.0.1` at `time:1971-06-01 12:13:14.987654321 +0100 CET`

Index

Examples

Constants

View Source
const (
	LevelTrace = Level(2 * slog.LevelDebug)
	LevelDebug = Level(slog.LevelDebug)
	LevelInfo  = Level(slog.LevelInfo)
	LevelWarn  = Level(slog.LevelWarn)
	LevelError = Level(slog.LevelError)
)
View Source
const (
	TDefault = sllm.TDefault
	TMillis  = TDefault | sllm.TMillis
	TMicros  = TDefault | sllm.TMicros
	TYear    = TDefault | sllm.TYear
	TYMillis = TMillis | sllm.TYear
	TYMicros = TMicros | sllm.TYear
)

Variables

This section is empty.

Functions

func Debug added in v0.13.0

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

func DebugContext added in v0.13.0

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

func Error added in v0.13.0

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

func ErrorContext added in v0.13.0

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

func Info added in v0.13.0

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

func InfoContext added in v0.13.0

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

func Log

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

func LogAttrs added in v0.13.0

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

func Trace added in v0.13.0

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

func TraceContext added in v0.13.0

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

func Warn added in v0.13.0

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

func WarnContext added in v0.13.0

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

Types

type AddSource added in v0.13.0

type AddSource int32
const (
	SrcFile AddSource = iota + 1
	SrcPath
	SrcStack
)

type Config added in v0.13.0

type Config struct {
	// contains filtered or unexported fields
}
var DefaultConfig Config

func (*Config) AddSource added in v0.13.0

func (cfg *Config) AddSource() AddSource

func (*Config) Clone added in v0.13.0

func (cfg *Config) Clone() *Config

func (*Config) Level added in v0.13.0

func (cfg *Config) Level() slog.Level

func (*Config) ParseFlag added in v0.14.0

func (cfg *Config) ParseFlag(f string) error

func (*Config) SetAddSource added in v0.13.0

func (cfg *Config) SetAddSource(s AddSource) *Config

func (*Config) SetLevel added in v0.13.0

func (cfg *Config) SetLevel(l Level) *Config

func (*Config) SetTimeFmt added in v0.13.0

func (cfg *Config) SetTimeFmt(f sllm.TimeFormat) *Config

func (*Config) SetWriter added in v0.13.0

func (cfg *Config) SetWriter(w io.Writer) *Config

func (*Config) TimeFmt added in v0.13.0

func (cfg *Config) TimeFmt() sllm.TimeFormat

func (*Config) Writer added in v0.13.0

func (cfg *Config) Writer() (w io.Writer)

type Level

type Level int

func (Level) String added in v0.13.0

func (l Level) String() string

type Logger

type Logger struct{ *slog.Logger }

func New

func New(cfg *Config) *Logger

func (*Logger) Enabled added in v0.12.0

func (l *Logger) Enabled(ctx context.Context, level Level) bool

func (*Logger) Log added in v0.14.1

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

func (*Logger) LogAttrs added in v0.14.1

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

func (*Logger) Trace

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

func (*Logger) TraceContext added in v0.13.0

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

func (*Logger) With added in v0.13.0

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

func (*Logger) WithGroup added in v0.13.0

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

type SllmHandler added in v0.13.0

type SllmHandler struct {
	Clock func() time.Time
	// contains filtered or unexported fields
}

func NewSllmHandler added in v0.13.0

func NewSllmHandler(cfg *Config) *SllmHandler

func (*SllmHandler) Enabled added in v0.13.0

func (h *SllmHandler) Enabled(_ context.Context, level slog.Level) bool

func (*SllmHandler) Handle added in v0.13.0

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

func (*SllmHandler) WithAttrs added in v0.13.0

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

func (*SllmHandler) WithGroup added in v0.13.0

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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