log

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeLogParam    = "code"
	MessageLogParam = "message"
	DetailsLogParam = "details"
	TraceLogParam   = "trace"
)

Log Params

View Source
const (
	TraceLevel = "trace"
	DebugLevel = "debug"
	InfoLevel  = "info"
	WarnLevel  = "warn"
	ErrorLevel = "error"
	FatalLevel = "fatal"
	PanicLevel = "panic"
)

Log Levels

Variables

This section is empty.

Functions

func InitLogger

func InitLogger(level Level, params []string)

InitLogger is used to initialize logger

func InitLoggerWithWriter

func InitLoggerWithWriter(level Level, w io.Writer, params []string)

InitLoggerWithWriter is used to initialize logger with a writer

Types

type Level

type Level string

type Logger

type Logger interface {
	// Msg sends the Logger with msg added as the message field if not empty.
	// NOTICE: once this method is called, the Logger should be disposed.
	// Calling Msg twice can have unexpected result.
	Msg(msg string)

	// Msgf sends the event with formatted msg added as the message field if not empty.
	// NOTICE: once this method is called, the Logger should be disposed.
	// Calling Msgf twice can have unexpected result.
	Msgf(format string, v ...interface{})

	// Send is equivalent to calling Msg("").
	// NOTICE: once this method is called, the Logger should be disposed.
	Send()

	// Bool adds the field key with val as a bool to the Logger context.
	Bool(key string, b bool) Logger

	// Bools adds the field key with val as a []bool to the Logger context.
	Bools(key string, b []bool) Logger

	// Bytes adds the field key with val as a string to the Logger context.
	// Runes outside of normal ASCII ranges will be hex-encoded in the resulting
	// JSON.
	Bytes(key string, val []byte) Logger

	// Err adds the field "error" with serialized err to the Logger context.
	// If err is nil, no field is added.
	Err(err error) Logger

	// Errs adds the field key with errs as an array of serialized errors to the
	// Logger context.
	Errs(key string, errs []error) Logger

	// Float32 adds the field key with f as a float32 to the Logger context.
	Float32(key string, f float32) Logger

	// Floats32 adds the field key with f as a []float32 to the Logger context.
	Floats32(key string, f []float32) Logger

	// Float64 adds the field key with f as a float64 to the Logger context.
	Float64(key string, f float64) Logger

	// Floats64 adds the field key with f as a []float64 to the Logger context.
	Floats64(key string, f []float64) Logger

	// Hex adds the field key with val as a hex string to the Logger context.
	Hex(key string, val []byte) Logger

	// Int adds the field key with i as a int to the Logger context.
	Int(key string, i int) Logger

	// Ints adds the field key with i as a []int to the Logger context.
	Ints(key string, i []int) Logger

	// Int8 adds the field key with i as a int8 to the Logger context.
	Int8(key string, i int8) Logger

	// Ints8 adds the field key with i as a []int8 to the Logger context.
	Ints8(key string, i []int8) Logger

	// Int16 adds the field key with i as a int16 to the Logger context.
	Int16(key string, i int16) Logger

	// Ints16 adds the field key with i as a []int16 to the Logger context.
	Ints16(key string, i []int16) Logger

	// Int32 adds the field key with i as a int32 to the Logger context.
	Int32(key string, i int32) Logger

	// Ints32 adds the field key with i as a []int32 to the Logger context.
	Ints32(key string, i []int32) Logger

	// Int64 adds the field key with i as a int64 to the Logger context.
	Int64(key string, i int64) Logger

	// Ints64 adds the field key with i as a []int64 to the Logger context.
	Ints64(key string, i []int64) Logger

	// RawJSON adds already encoded JSON to the log line under key.
	// No sanity check is performed on b; it must not contain carriage returns and
	// be valid JSON.
	RawJSON(key string, b []byte) Logger

	// Stack enables stack trace printing for the error passed to Err().
	Stack() Logger

	// Str adds the field key with val as a string to the Logger context.
	Str(key, val string) Logger

	// Strs adds the field key with values as a []string to the Logger context.
	Strs(key string, values []string) Logger

	// Stringer adds the field key with val.String() (or null if val is nil)
	// to the Logger context.
	Stringer(key string, val fmt.Stringer) Logger

	// Stringers adds the field key with values where each individual val
	// is used as val.String() (or null if val is empty) to the Logger
	// context.
	Stringers(key string, values []fmt.Stringer) Logger

	// Uint adds the field key with i as a uint to the Logger context.
	Uint(key string, i uint) Logger

	// Uints adds the field key with i as a []uint to the Logger context.
	Uints(key string, i []uint) Logger

	// Uint8 adds the field key with i as a uint8 to the Logger context.
	Uint8(key string, i uint8) Logger

	// Uints8 adds the field key with i as a []uint8 to the Logger context.
	Uints8(key string, i []uint8) Logger

	// Uint16 adds the field key with i as a uint16 to the Logger context.
	Uint16(key string, i uint16) Logger

	// Uints16 adds the field key with i as a []int16 to the Logger context.
	Uints16(key string, i []uint16) Logger

	// Uint32 adds the field key with i as a uint32 to the Logger context.
	Uint32(key string, i uint32) Logger

	// Uints32 adds the field key with i as a []int32 to the Logger context.
	Uints32(key string, i []uint32) Logger

	// Uint64 adds the field key with i as a uint64 to the Logger context.
	Uint64(key string, i uint64) Logger

	// Uints64 adds the field key with i as a []int64 to the Logger context.
	Uints64(key string, i []uint64) Logger

	// Interface adds the field key with value marshaled using reflection.
	Interface(key string, i interface{}) Logger

	// Any adds the field key with value marshaled using reflection.
	Any(key string, a any) Logger
}

Logger is the interface to the logging possibilities.

func Debug

func Debug(ctx context.Context) Logger

Debug is the for debug log

func Error

func Error(ctx context.Context) Logger

Error is the for error log

func ErrorWarn

func ErrorWarn(ctx context.Context, err error) Logger

ErrorWarn checks for the error object. In case it is corresponding to a 4XX status code, it logs it as warning. Otherwise, it logs it as an error.

func Fatal

func Fatal(ctx context.Context) Logger

Fatal is the for fatal log

func Info

func Info(ctx context.Context) Logger

Info is the for info log

func Panic

func Panic(ctx context.Context) Logger

Panic is the for panic log

func Trace

func Trace(ctx context.Context) Logger

Trace is the for trace log

func Warn

func Warn(ctx context.Context) Logger

Warn is the for warn log

Jump to

Keyboard shortcuts

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