log

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {
	// Key for a given field
	Key string
	// Type of a given field
	Type FieldType
	// Value of the given field
	Value interface{}
	// optmizations for string & int
	Integer int64
	String  string
}

Field defines a standard Key-Value pair used to populate the value for the logger

func Bool

func Bool(key string, value bool) Field

Bool is a wrapper for boolean values for logging

func Error

func Error(err error) Field

Error is wrapper for error values for logging

func Float

func Float(key string, value float64) Field

Float value is for floating point fields

func Int

func Int(key string, value int) Field

Int wrapper for logging

func Int64

func Int64(key string, value int64) Field

Int64 is a wrapper int64 values for logging

func Reflect

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

Reflect returns a field for which the value is undetermined

func String

func String(key string, value string) Field

String is logger wrapper for string

type FieldType

type FieldType int

FieldType defines the type for a field

const (
	UNKNOWN FieldType = iota
	BOOL
	INT
	INT64
	STRING
	ERROR
	FLOAT
)

Field Types supported by Logger

type Logger

type Logger interface {
	// Should also implement default kit.log.Logger interface
	kit_log.Logger

	// Leveled Logging
	Info(string, ...Field)
	Warn(string, ...Field)
	Error(string, ...Field)
	Panic(string, ...Field)
	Fatal(string, ...Field)
	Debug(string, ...Field)

	Infof(string, ...interface{})
	Errorf(string, ...interface{})
	Debugf(string, ...interface{})

	// Flush the logs
	Flush() error

	// Default Fields
	With(...Field) Logger
	WithContext(cx context.Context) context.Context
}

Logger defines standard set of functions supported by logger and used across the Base Package

func FromCtx

func FromCtx(cx context.Context) Logger

Ctx returns the logger wrapped in the Context

func NewNoopLogger

func NewNoopLogger() Logger

func NewZapLogger

func NewZapLogger(
	options ...ZapLoggerOption,
) (Logger, error)

NewZapLogger returns a default implementaiton of log.Logger interface using uber/zap as core layer

func NewZeroLogger

func NewZeroLogger(options ...ZeroLoggerOption) (Logger, error)

type ZapLoggerOption

type ZapLoggerOption func(*zapLogger)

func ZapWithAppendedOutput

func ZapWithAppendedOutput(outputs []string) ZapLoggerOption

ZapWithAppendedOutput is option to add additional output to list of existing output destination

func ZapWithEncoding

func ZapWithEncoding(encoding string) ZapLoggerOption

ZapWithEncoding is option to set encoding for zap based logger

func ZapWithLevel

func ZapWithLevel(level string) ZapLoggerOption

ZapWithLevel is option to set level for Zap Based Logger

func ZapWithOutput

func ZapWithOutput(outputs []string) ZapLoggerOption

ZapWithOutput is option to set output paths for zap based logger

type ZeroLoggerAlerter

type ZeroLoggerAlerter func(missed int)

Alerter is used to notify, how many messages were dropped

example:
func(missed int) {
	fmt.Printf("Logger Dropped %d messages", missed)
}

type ZeroLoggerOption

type ZeroLoggerOption func(*zeroLoggerConfig) error

func ZeroLoggerWithAsyncSink

func ZeroLoggerWithAsyncSink(
	size int,
	pollInterval time.Duration,
	alerter ZeroLoggerAlerter,
) ZeroLoggerOption

func ZeroLoggerWithCaller

func ZeroLoggerWithCaller() ZeroLoggerOption

func ZeroLoggerWithFields

func ZeroLoggerWithFields(fields ...Field) ZeroLoggerOption

func ZeroLoggerWithLevel

func ZeroLoggerWithLevel(level string) ZeroLoggerOption

func ZeroLoggerWithOutputs

func ZeroLoggerWithOutputs(outputs []string) ZeroLoggerOption

func ZeroLoggerWithStackTraceInError

func ZeroLoggerWithStackTraceInError() ZeroLoggerOption

Jump to

Keyboard shortcuts

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