log

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2023 License: MIT Imports: 9 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Out io.Writer = os.Stderr
)

Functions

func Configure

func Configure(config Config) error

func KvParse

func KvParse(line string) map[string]string

func KvParseAll

func KvParseAll(l string) []map[string]string

Types

type Config

type Config struct {
	Requests *bool    `json:"requests"`
	Level    string   `json:"level"`
	Format   string   `json:"format"`
	PoolSize uint16   `json:"pool_size"`
	KV       KvConfig `json:"kv"`
}

type Factory

type Factory func(release func(Logger), level Level, request bool) Logger

func KvFactory

func KvFactory(maxSize uint32) Factory

type Field

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

func NewField

func NewField() *Field

func (*Field) Finalize

func (f *Field) Finalize() Field

just return Field so that it can be used in chaining

func (*Field) Int

func (f *Field) Int(key string, value int) *Field

func (*Field) KV

func (f *Field) KV() []byte

func (*Field) String

func (f *Field) String(key string, value string) *Field

type KvConfig

type KvConfig struct {
	MaxSize uint32 `json:"max_size"`
}

type KvLogger

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

func NewKvLogger

func NewKvLogger(maxSize uint32, release func(Logger), level Level, requests bool) *KvLogger

func (*KvLogger) Binary added in v0.0.7

func (l *KvLogger) Binary(key string, value []byte) Logger

func (*KvLogger) Bool added in v0.0.6

func (l *KvLogger) Bool(key string, value bool) Logger

Add a field (key=value) where value is a boolean

func (*KvLogger) Bytes

func (l *KvLogger) Bytes() []byte

Get the bytes from the logger. This is only valid before Log is called (after log is called, you'll get an empty slice). Only really useful for testing.

func (*KvLogger) Err

func (l *KvLogger) Err(err error) Logger

Add a field (key=value) where value is an error

func (*KvLogger) Error

func (l *KvLogger) Error(ctx string) Logger

Log an error-level message.

func (*KvLogger) Fatal

func (l *KvLogger) Fatal(ctx string) Logger

Log an fatal-level message.

func (*KvLogger) Field

func (l *KvLogger) Field(field Field) Logger

func (*KvLogger) Fixed

func (l *KvLogger) Fixed()

Logger will _always_ include this data. Meant to be used with the Field builder. Even once released to the pool and re-checked out, this data will still be in the logger. For checkout-specific data, see MultiUse().

func (*KvLogger) Info

func (l *KvLogger) Info(ctx string) Logger

Log an info-level message.

func (*KvLogger) Int

func (l *KvLogger) Int(key string, value int) Logger

Add a field (key=value) where value is an int

func (*KvLogger) Int64

func (l *KvLogger) Int64(key string, value int64) Logger

Add a field (key=value) where value is an int

func (*KvLogger) Log

func (l *KvLogger) Log()

Write the log to our globally configured writer

func (*KvLogger) LogTo

func (l *KvLogger) LogTo(out io.Writer)

func (*KvLogger) MultiUse

func (l *KvLogger) MultiUse() Logger

Similar to Fixed, but exists only while checked out

func (*KvLogger) Release

func (l *KvLogger) Release()

func (*KvLogger) Request added in v0.0.6

func (l *KvLogger) Request(route string) Logger

Log a request message.

func (*KvLogger) Reset

func (l *KvLogger) Reset()

func (*KvLogger) String

func (l *KvLogger) String(key string, value string) Logger

Add a field (key=value) where value is a string

func (*KvLogger) Warn

func (l *KvLogger) Warn(ctx string) Logger

Log an warn-level message.

type Level

type Level uint8
const (
	INFO Level = iota
	WARN
	ERROR
	FATAL
	NONE
)

type Logger

type Logger interface {
	// Actually log the data to the configured output
	// If the logger was not configured for MultiUse, this
	// must release the logger back to the pool (if any).
	Log()

	// Log to the specific writer
	LogTo(io.Writer)

	// Resets the logger, without releasing it back to the pool.
	// Reset must not erased any fixed data
	Reset()

	// Releases the logger back to the pool, if one is configured.
	Release()

	// Gets the log data
	Bytes() []byte

	// Set the level and context for a new log entry
	Info(ctx string) Logger
	Warn(ctx string) Logger
	Error(ctx string) Logger
	Fatal(ctx string) Logger
	Request(route string) Logger

	// Log an error
	Err(err error) Logger

	// Any data already in the logger will be including in _every_
	// message ever generated from this logger. This data survives both
	// a reset and a release.
	// As an example of where this could be used is a project owned loggers
	// in which case these loggers could have the project_id always included
	// in any log entry.
	Fixed()

	// Any data already in the logger will be including in _every_
	// message generated until the logger is released. This data survives a
	// a reset but not a release.
	// This is meant to be used for a request-owned logger where every entry
	// logged with the logger has request_id.
	MultiUse() Logger

	// Add an int value to the current entry
	Int(key string, value int) Logger

	// Add an int64 value to the current entry
	Int64(key string, value int64) Logger

	// Add a string value to the current entry
	String(key string, value string) Logger

	// Add a binary value to the current entry
	Binary(key string, value []byte) Logger

	// Add a boolean value to the current entry
	Bool(key string, value bool) Logger

	// Log a field
	Field(field Field) Logger
}

func Checkout

func Checkout() Logger

func Error

func Error(ctx string) Logger

func Fatal

func Fatal(ctx string) Logger

func Info

func Info(ctx string) Logger

func Request added in v0.0.6

func Request(route string) Logger

func Warn

func Warn(ctx string) Logger

type Noop

type Noop struct {
}

func (Noop) Binary added in v0.0.7

func (n Noop) Binary(key string, value []byte) Logger

func (Noop) Bool added in v0.0.6

func (n Noop) Bool(key string, value bool) Logger

func (Noop) Bytes

func (_ Noop) Bytes() []byte

func (Noop) Err

func (n Noop) Err(err error) Logger

func (Noop) Error

func (n Noop) Error(ctx string) Logger

func (Noop) Fatal

func (n Noop) Fatal(ctx string) Logger

func (Noop) Field

func (n Noop) Field(field Field) Logger

func (Noop) Fixed

func (n Noop) Fixed()

func (Noop) Info

func (n Noop) Info(ctx string) Logger

func (Noop) Int

func (n Noop) Int(key string, value int) Logger

func (Noop) Int64

func (n Noop) Int64(key string, value int64) Logger

func (Noop) Log

func (_ Noop) Log()

func (Noop) LogTo

func (_ Noop) LogTo(io.Writer)

func (Noop) MultiUse

func (n Noop) MultiUse() Logger

func (Noop) Release

func (_ Noop) Release()

func (Noop) Request added in v0.0.6

func (n Noop) Request(route string) Logger

func (Noop) Reset

func (_ Noop) Reset()

func (Noop) String

func (n Noop) String(key string, value string) Logger

func (Noop) Warn

func (n Noop) Warn(ctx string) Logger

type Pool

type Pool struct {
	*concurrent.Pool[Logger]
	// contains filtered or unexported fields
}

func NewPool

func NewPool(count uint16, level Level, requests bool, factory Factory, field *Field) *Pool

func (*Pool) Error

func (p *Pool) Error(ctx string) Logger

func (*Pool) Fatal

func (p *Pool) Fatal(ctx string) Logger

func (*Pool) Info

func (p *Pool) Info(ctx string) Logger

func (*Pool) Request added in v0.0.6

func (p *Pool) Request(route string) Logger

func (*Pool) Warn

func (p *Pool) Warn(ctx string) Logger

type StructuredError

type StructuredError struct {
	Data map[string]any `json:"data"`
	Err  error          `json:"err"`
	Code int            `json:"code"`
}

An error that's designed to be logged in a more structured manner

func Err

func Err(code int, err error) *StructuredError

func ErrData added in v0.0.6

func ErrData(code int, err error, data map[string]any) *StructuredError

func Errf

func Errf(code int, format string, args ...any) *StructuredError

func (*StructuredError) Binary added in v0.0.7

func (e *StructuredError) Binary(key string, value []byte) *StructuredError

func (*StructuredError) Error

func (e *StructuredError) Error() string

func (*StructuredError) Int

func (e *StructuredError) Int(key string, value int) *StructuredError

func (*StructuredError) String

func (e *StructuredError) String(key string, value string) *StructuredError

func (*StructuredError) Unwrap added in v0.0.7

func (e *StructuredError) Unwrap() error

Jump to

Keyboard shortcuts

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