log

package
v0.0.6-rc.5 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TraceString = "trace"
	DebugString = "debug"
	InfoString  = "info"
	WarnString  = "warn"
	ErrorString = "error"
	FatalString = "fatal"
)

String values for standard log levels

View Source
const (
	// DefaultErrorFieldName is the default field name used for errors
	DefaultErrorFieldName = "error"
)

Variables

This section is empty.

Functions

func WriteAt

func WriteAt(l Structured, lvl Level, msg string, fields ...Field) error

WriteAt is a helper method that checks logger and writes message at given level

Types

type Field

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

Field stores one structured logging field

func Any

func Any(key string, value interface{}) Field

Any tries to deduce interface{} underlying type and constructs Field from it. Use of this function is ok only for the sole purpose of not repeating its entire code or parts of it in user's code (when you need to log interface{} types with unknown content). Otherwise please use specialized functions. nolint: gocyclo

func Array

func Array(key string, value interface{}) Field

Array constructs field of array type

func Binary

func Binary(key string, value []byte) Field

Binary constructs field of []byte type

func Bool

func Bool(key string, value bool) Field

Bool constructs field of bool type

func Bools

func Bools(key string, value []bool) Field

Bools constructs Field from []bool

func ByteString

func ByteString(key string, value []byte) Field

ByteString constructs field of bytes that could represent UTF-8 string

func Context

func Context(ctx context.Context) Field

Context constructs field for lazy context fields evaluation if possible

func Duration

func Duration(key string, value time.Duration) Field

Duration constructs field of time.Duration type

func Durations

func Durations(key string, value []time.Duration) Field

Durations constructs Field from []time.Duration

func Error

func Error(value error) Field

Error constructs field of error type with default field name

func Errors

func Errors(key string, value []error) Field

Errors constructs Field from []error

func Float32

func Float32(key string, value float32) Field

Float32 constructs Field from float32

func Float32s

func Float32s(key string, value []float32) Field

Float32s constructs Field from []float32

func Float64

func Float64(key string, value float64) Field

Float64 constructs Field from float64

func Float64s

func Float64s(key string, value []float64) Field

Float64s constructs Field from []float64

func Int

func Int(key string, value int) Field

Int constructs Field from int

func Int16

func Int16(key string, value int16) Field

Int16 constructs Field from int16

func Int16s

func Int16s(key string, value []int16) Field

Int16s constructs Field from []int16

func Int32

func Int32(key string, value int32) Field

Int32 constructs Field from int32

func Int32s

func Int32s(key string, value []int32) Field

Int32s constructs Field from []int32

func Int64

func Int64(key string, value int64) Field

Int64 constructs Field from int64

func Int64s

func Int64s(key string, value []int64) Field

Int64s constructs Field from []int64

func Int8

func Int8(key string, value int8) Field

Int8 constructs Field from int8

func Int8s

func Int8s(key string, value []int8) Field

Int8s constructs Field from []int8

func Ints

func Ints(key string, value []int) Field

Ints constructs Field from []int

func NamedError

func NamedError(key string, value error) Field

NamedError constructs field of error type

func Nil

func Nil(key string) Field

Nil constructs field of nil type

func Reflect

func Reflect(key string, value interface{}) Field

Reflect constructs field of unknown type

func Sprintf

func Sprintf(key, format string, args ...interface{}) Field

Sprintf constructs field of string type with formatting

func String

func String(key, value string) Field

String constructs field of string type

func Strings

func Strings(key string, value []string) Field

Strings constructs Field from []string

func Time

func Time(key string, value time.Time) Field

Time constructs field of time.Time type

func Times

func Times(key string, value []time.Time) Field

Times constructs Field from []time.Time

func UInt

func UInt(key string, value uint) Field

UInt constructs Field from uint

func UInt16

func UInt16(key string, value uint16) Field

UInt16 constructs Field from uint16

func UInt16s

func UInt16s(key string, value []uint16) Field

UInt16s constructs Field from []uint16

func UInt32

func UInt32(key string, value uint32) Field

UInt32 constructs Field from uint32

func UInt32s

func UInt32s(key string, value []uint32) Field

UInt32s constructs Field from []uint32

func UInt64

func UInt64(key string, value uint64) Field

UInt64 constructs Field from uint64

func UInt64s

func UInt64s(key string, value []uint64) Field

UInt64s constructs Field from []uint64

func UInt8

func UInt8(key string, value uint8) Field

UInt8 constructs Field from uint8

func UInt8s

func UInt8s(key string, value []uint8) Field

UInt8s constructs Field from []uint8

func UInts

func UInts(key string, value []uint) Field

UInts constructs Field from []uint

func (Field) Any

func (f Field) Any() interface{}

Any returns contained data as interface{} nolint: gocyclo

func (Field) Binary

func (f Field) Binary() []byte

Binary constructs field of []byte

func (Field) Bool

func (f Field) Bool() bool

Bool returns field bool

func (Field) Duration

func (f Field) Duration() time.Duration

Duration returns field time.Duration

func (Field) Error

func (f Field) Error() error

Error constructs field of error type

func (Field) Float

func (f Field) Float() float64

Float returns field float64

func (Field) Interface

func (f Field) Interface() interface{}

Interface returns field interface

func (Field) Key

func (f Field) Key() string

Key returns field key

func (Field) Signed

func (f Field) Signed() int64

Signed returns field int64

func (Field) String

func (f Field) String() string

String returns field string

func (Field) Time

func (f Field) Time() time.Time

Time returns field time.Time

func (Field) Type

func (f Field) Type() FieldType

Type returns field type

func (Field) Unsigned

func (f Field) Unsigned() uint64

Unsigned returns field uint64

type FieldType

type FieldType int

FieldType is a type of data Field can represent

const (
	// FieldTypeNil is for a pure nil
	FieldTypeNil FieldType = iota
	// FieldTypeString is for a string
	FieldTypeString
	// FieldTypeBinary is for a binary array
	FieldTypeBinary
	// FieldTypeBoolean is for boolean
	FieldTypeBoolean
	// FieldTypeSigned is for signed integers
	FieldTypeSigned
	// FieldTypeUnsigned is for unsigned integers
	FieldTypeUnsigned
	// FieldTypeFloat is for float
	FieldTypeFloat
	// FieldTypeTime is for time.Time
	FieldTypeTime
	// FieldTypeDuration is for time.Duration
	FieldTypeDuration
	// FieldTypeError is for an error
	FieldTypeError
	// FieldTypeArray is for an array of any type
	FieldTypeArray
	// FieldTypeAny is for any type
	FieldTypeAny
	// FieldTypeReflect is for unknown types
	FieldTypeReflect
	// FieldTypeByteString is for a bytes that can be represented as UTF-8 string
	FieldTypeByteString
	// FieldTypeContext wraps context for lazy context fields evaluation if possible
	FieldTypeContext
)

type Fmt

type Fmt interface {
	// contains filtered or unexported methods
}

Fmt provides interface for logging using fmt formatter.

type Level

type Level int

Level of logging

const (
	TraceLevel Level = iota
	DebugLevel
	InfoLevel
	WarnLevel
	ErrorLevel
	FatalLevel
)

Standard log levels

func Levels

func Levels() (l []Level)

func ParseLevel

func ParseLevel(l string) (Level, error)

ParseLevel parses log level from string. Returns ErrUnknownLevel for unknown log level.

func (Level) MarshalText

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

MarshalText marshals level to text

func (*Level) Set

func (l *Level) Set(v string) error

Set implements flag.Value interface

func (Level) String

func (l Level) String() string

String implements Stringer interface for Level

func (*Level) UnmarshalText

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

UnmarshalText unmarshals level from text

type Logger

type Logger interface {
	// contains filtered or unexported methods
}

Logger is the universal logger that can do everything.

func AddCallerSkip

func AddCallerSkip(l Logger, skip int) Logger

AddCallerSkip for loggers that implement LoggerAddCallerSkip interface, returns logger that adds caller skip to each log entry. Otherwise returns same logger.

func With

func With(l Logger, fields ...Field) Logger

With for loggers that implement LoggerWith interface, returns logger that always adds provided key/value to every log entry. Otherwise returns same logger.

type LoggerAddCallerSkip

type LoggerAddCallerSkip interface {
	// AddCallerSkip implements 'AddCallerSkip'
	AddCallerSkip(skip int) Logger
}

LoggerAddCallerSkip is an interface for 'AddCallerSkip' function

type LoggerWith

type LoggerWith interface {
	// With implements 'With'
	With(fields ...Field) Logger
}

LoggerWith is an interface for 'With' function LoggerWith provides interface for logger modifications.

type Structured

type Structured interface {
	// contains filtered or unexported methods
}

Structured provides interface for logging using fields.

Directories

Path Synopsis
compat
zap

Jump to

Keyboard shortcuts

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