logger

package
v0.0.0-...-b0c7f7e Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogfmtTimestampLayout = "2006-01-02 15:04:05.000"

	LogfmtMaxLenLoggerID   = 8
	LogfmtMaxLenLoggerName = 10
)

Variables

View Source
var (
	ConsoleHandler = NewDefaultHandler(
		"__consoleHandler",
		LevelTrace,
		NewLogfmtFormatter(&LogfmtFormatterOptions{WithColors: true}),
		os.Stdout,
	)
)

Functions

This section is empty.

Types

type DefaultHandler

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

func NewDefaultHandler

func NewDefaultHandler(name string, level Level, f Formatter, w io.Writer) *DefaultHandler

func (*DefaultHandler) Enabled

func (h *DefaultHandler) Enabled(level Level) bool

func (*DefaultHandler) Formatter

func (h *DefaultHandler) Formatter() Formatter

func (*DefaultHandler) Level

func (h *DefaultHandler) Level() Level

func (*DefaultHandler) Name

func (h *DefaultHandler) Name() string

func (*DefaultHandler) SetLevel

func (h *DefaultHandler) SetLevel(level Level)

func (*DefaultHandler) Writer

func (h *DefaultHandler) Writer() io.Writer

type Formatter

type Formatter interface {
	Format(*buffer.Buffer, *Record)
}

type Handler

type Handler interface {
	Name() string
	Enabled(Level) bool
	Formatter() Formatter
	Writer() io.Writer
}

type Level

type Level int
const (
	LevelTrace   Level = -2
	LevelDebug   Level = -1
	LevelInfo    Level = 0 // Zero LevelVar
	LevelNotice  Level = 1
	LevelWarning Level = 2
	LevelError   Level = 3
)

func StringToLevel

func StringToLevel(level string) Level

func (Level) Level

func (level Level) Level() Level

type LevelVar

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

func (*LevelVar) Level

func (lv *LevelVar) Level() Level

func (*LevelVar) Set

func (lv *LevelVar) Set(level Level)

type LogfmtFormatter

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

func NewLogfmtFormatter

func NewLogfmtFormatter(opts *LogfmtFormatterOptions) *LogfmtFormatter

func (*LogfmtFormatter) Format

func (f *LogfmtFormatter) Format(buf *buffer.Buffer, rec *Record)

type LogfmtFormatterOptions

type LogfmtFormatterOptions struct {
	TimestampLayout  string
	WithColors       bool
	MaxLenLoggerID   int
	MaxLenLoggerName int
}

type Logger

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

func New

func New(id, name string) *Logger

func (*Logger) AddHandler

func (l *Logger) AddHandler(h Handler)

func (*Logger) Debug

func (l *Logger) Debug(msg string, kvs ...kv.KeyValue)

func (*Logger) Error

func (l *Logger) Error(msg string, kvs ...kv.KeyValue)

func (*Logger) FormatAndWrite

func (l *Logger) FormatAndWrite(level Level, msg string, kvs ...kv.KeyValue)

func (*Logger) Info

func (l *Logger) Info(msg string, kvs ...kv.KeyValue)

func (*Logger) Level

func (l *Logger) Level() Level

func (*Logger) Log

func (l *Logger) Log(level Level, msg string, kvs ...kv.KeyValue)

func (*Logger) LogArgs

func (l *Logger) LogArgs(level Level, msg string, args ...any)

func (*Logger) New

func (l *Logger) New(id, name string) *Logger

func (*Logger) Notice

func (l *Logger) Notice(msg string, kvs ...kv.KeyValue)

func (*Logger) RemoveHandler

func (l *Logger) RemoveHandler(name string)

func (*Logger) SetLevel

func (l *Logger) SetLevel(level Level)

func (*Logger) Trace

func (l *Logger) Trace(msg string, kvs ...kv.KeyValue)

func (*Logger) Warning

func (l *Logger) Warning(msg string, kvs ...kv.KeyValue)

func (*Logger) With

func (l *Logger) With(kvs ...kv.KeyValue) *Logger

type Record

type Record struct {
	LoggerID   string
	LoggerName string
	Timestamp  time.Time
	Level      Level
	Message    string
	KeyValues  []kv.KeyValue
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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