logger

package
v0.0.0-...-052ef2a Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const CacheLinePad = unsafe.Sizeof(cpu.CacheLinePad{})
View Source
const TestMessage = "Test logging, but use a somewhat realistic message length."

Variables

View Source
var (
	ErrFull      = errors.New("full")
	ErrTimeout   = errors.New("timeout")
	ErrEmptyData = errors.New("empty data")
	ErrTooBig    = errors.New("too big")
)
View Source
var (
	DurationAsString   = true
	RawFieldName       = "raw"
	DataFieldName      = "data"
	DurationFieldName  = "dur"
	DurationsFieldName = "durs"
	ErrorsFieldName    = "errors"

	EmptyMessage = ""
)
View Source
var (
	TestTime     = time.Date(2022, time.May, 1, 0, 0, 0, 0, time.UTC)
	TestString   = "7e3b3b2aaeff56a7108fe11e154200dd/7819479873059528190"
	TestInt      = 32768
	TestDuration = 23 * time.Second
	TestError    = errors.New("fail")
)

Functions

func AppendRecord

func AppendRecord(b []byte, ts int64, level Level, fn *FuncInfo, msg string) []byte

func Err

func Err()

func FuncFromPointer

func FuncFromPointer(p unsafe.Pointer) func()

func FuncToPC

func FuncToPC(fn func()) uintptr

func FuncToPCUnsafe

func FuncToPCUnsafe(p unsafe.Pointer) uintptr

func FuncToPointer

func FuncToPointer(fn func()) unsafe.Pointer

func Info

func Info()

func Info0

func Info0()

func Log

func Log(level Level, msg string)

Types

type Attr

type Attr[T AttrType] struct {
	Key   string
	Value T
}

An Attr is a key-value pair.

func (*Attr[T]) Kind

func (a *Attr[T]) Kind() Kind

type AttrType

type AttrType interface {
	string | int8 | int16 | int32 | int64 | uint8 |
		uint16 | uint32 | uint64 | float32 | float64 |
		time.Duration | time.Time
}

type Event

type Event struct {
}

type Flags

type Flags uint8
const (
	HighFrequency Flags = 1 << iota
)

func (Flags) Clear

func (f Flags) Clear(b, flag Flags) Flags

func (Flags) Has

func (f Flags) Has(b, flag Flags) bool

func (Flags) IsHighFrequency

func (f Flags) IsHighFrequency() bool

func (Flags) Set

func (f Flags) Set(b, flag Flags) Flags

func (Flags) Toggle

func (f Flags) Toggle(b, flag Flags) Flags

type FuncInfo

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

func GetMethodSlow

func GetMethodSlow(
	object interface{},
	methodWrapperPC uintptr,
	methodName string,
) *FuncInfo

func (*FuncInfo) Data

func (f *FuncInfo) Data() any

func (*FuncInfo) Entry

func (f *FuncInfo) Entry() uintptr

func (*FuncInfo) File

func (f *FuncInfo) File() string

func (*FuncInfo) Formatted

func (f *FuncInfo) Formatted() string

func (*FuncInfo) Line

func (f *FuncInfo) Line() int

func (*FuncInfo) Method

func (f *FuncInfo) Method() reflect.Method

func (*FuncInfo) MethodName

func (f *FuncInfo) MethodName() string

func (*FuncInfo) Name

func (f *FuncInfo) Name() string

func (*FuncInfo) NumIn

func (f *FuncInfo) NumIn() int

func (*FuncInfo) NumOut

func (f *FuncInfo) NumOut() int

func (*FuncInfo) PC

func (f *FuncInfo) PC() uintptr

func (*FuncInfo) Receiver

func (f *FuncInfo) Receiver() string

func (*FuncInfo) ReceiverSize

func (f *FuncInfo) ReceiverSize() uintptr

func (*FuncInfo) SetData

func (f *FuncInfo) SetData(data any)

func (*FuncInfo) String

func (f *FuncInfo) String() string

type FuncInfoMap

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

func NewFuncInfoMap

func NewFuncInfoMap() *FuncInfoMap

func (*FuncInfoMap) GetForFunc

func (fip *FuncInfoMap) GetForFunc(fn func()) *FuncInfo

func (*FuncInfoMap) GetForPC

func (fip *FuncInfoMap) GetForPC(pc uintptr) *FuncInfo

func (*FuncInfoMap) GetMethod

func (fip *FuncInfoMap) GetMethod(methodWrapperPC uintptr) *FuncInfo

func (*FuncInfoMap) GetMethodSlow

func (fip *FuncInfoMap) GetMethodSlow(
	object interface{},
	methodWrapperPC uintptr,
	methodName string,
) *FuncInfo

type Kind

type Kind uint8

Kind is the kind of Value.

const (
	KindUnknown Kind = iota
	KindBool
	KindInt8
	KindInt16
	KindInt32
	KindInt64
	KindUint8
	KindUint16
	KindUint32
	KindUint64
	KindFloat32
	KindFloat64
	KindDuration
	KindTime
	KindString
)

type Level

type Level int8

A Level is the importance or severity of a log event. The higher the level, the more important or severe the event.

const (
	LevelDebug Level = -4
	LevelInfo  Level = 0
	LevelWarn  Level = 4
	LevelError Level = 8
)

Second, we wanted to make it easy to use levels to specify logger verbosity. Since a larger level means a more severe event, a logger that accepts events with smaller (or more negative) level means a more verbose logger. Logger verbosity is thus the negation of event severity, and the default verbosity of 0 accepts all events at least as severe as INFO.

Third, we wanted some room between levels to accommodate schemes with named levels between ours. For example, Google Cloud Logging defines a Notice level between Info and Warn. Since there are only a few of these intermediate levels, the gap between the numbers need not be large. Our gap of 4 matches OpenTelemetry's mapping. Subtracting 9 from an OpenTelemetry level in the DEBUG, INFO, WARN and ERROR ranges converts it to the corresponding slog Level range. OpenTelemetry also has the names TRACE and FATAL, which slog does not. But those OpenTelemetry levels can still be represented as slog Levels by using the appropriate integers.

Names for common levels.

func (Level) Level

func (l Level) Level() Level

Level returns the receiver. It implements Leveler.

func (Level) MarshalJSON

func (l Level) MarshalJSON() ([]byte, error)

MarshalJSON implements encoding/json.Marshaler by quoting the output of Level.String.

func (Level) MarshalText

func (l Level) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler by calling Level.String.

func (Level) String

func (l Level) String() string

String returns a name for the level. If the level has a name, then that name in uppercase is returned. If the level is between named values, then an integer is appended to the uppercased name. Examples:

LevelWarn.String() => "WARN"
(LevelInfo+2).String() => "INFO+2"

func (*Level) UnmarshalJSON

func (l *Level) UnmarshalJSON(data []byte) error

UnmarshalJSON implements encoding/json.Unmarshaler It accepts any string produced by Level.MarshalJSON, ignoring case. It also accepts numeric offsets that would result in a different string on output. For example, "Error-8" would marshal as "INFO".

func (*Level) UnmarshalText

func (l *Level) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler. It accepts any string produced by Level.MarshalText, ignoring case. It also accepts numeric offsets that would result in a different string on output. For example, "Error-8" would marshal as "INFO".

type LevelVar

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

A LevelVar is a Level variable, to allow a Handler level to change dynamically. It implements Leveler as well as a Set method, and it is safe for use by multiple goroutines. The zero LevelVar corresponds to LevelInfo.

func (*LevelVar) Level

func (v *LevelVar) Level() Level

Level returns v's level.

func (*LevelVar) MarshalText

func (v *LevelVar) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler by calling Level.MarshalText.

func (*LevelVar) Set

func (v *LevelVar) Set(l Level)

Set sets v's level to l.

func (*LevelVar) String

func (v *LevelVar) String() string

func (*LevelVar) UnmarshalText

func (v *LevelVar) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler by calling Level.UnmarshalText.

type Leveler

type Leveler interface {
	Level() Level
}

A Leveler provides a Level value.

As Level itself implements Leveler, clients typically supply a Level value wherever a Leveler is needed, such as in HandlerOptions. Clients who need to vary the level dynamically can provide a more complex Leveler implementation such as *LevelVar.

type Logger

type Logger struct {
}

type Record

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

func (Record) BaseSize

func (r Record) BaseSize() int

func (Record) Flags

func (r Record) Flags() Flags

func (Record) Level

func (r Record) Level() Level

func (Record) Size

func (r Record) Size() int

type RecordAttr

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

func (*RecordAttr) Kind

func (ra *RecordAttr) Kind() Kind

type RecordAttributes

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

type RecordBuilder

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

func AllocRecordBuilder

func AllocRecordBuilder() RecordBuilder

func (RecordBuilder) Msg

func (r RecordBuilder) Msg(msg string, a ...any)

func (RecordBuilder) Msgf

func (r RecordBuilder) Msgf(format string, a ...any)

func (RecordBuilder) Reset

func (r RecordBuilder) Reset() RecordBuilder

func (RecordBuilder) Size

func (r RecordBuilder) Size(size uint16) RecordBuilder

func (RecordBuilder) Str

func (r RecordBuilder) Str(name string, value string) RecordBuilder

func (RecordBuilder) Strf

func (r RecordBuilder) Strf(name string, value string, a ...any) RecordBuilder

func (RecordBuilder) TimeHF

func (r RecordBuilder) TimeHF() RecordBuilder

type RecordHeader

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

func (*RecordHeader) AttrReader

func (r *RecordHeader) AttrReader()

func (*RecordHeader) Caller

func (r *RecordHeader) Caller() string

func (*RecordHeader) Msg

func (r *RecordHeader) Msg() string

func (*RecordHeader) Source

func (r *RecordHeader) Source() string

Directories

Path Synopsis
Package slog provides structured logging, in which log records include a message, a severity level, and various other attributes expressed as key-value pairs.
Package slog provides structured logging, in which log records include a message, a severity level, and various other attributes expressed as key-value pairs.
benchmarks
Package benchmarks contains benchmarks for slog.
Package benchmarks contains benchmarks for slog.
internal/buffer
Package buffer provides a pool-allocated byte buffer.
Package buffer provides a pool-allocated byte buffer.
internal/testutil
Package testutil contains support functions for testing.
Package testutil contains support functions for testing.

Jump to

Keyboard shortcuts

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