logger

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: AGPL-3.0 Imports: 13 Imported by: 99

Documentation

Overview

Package logger

Logger Interface Use instance of logger instead of exported functions

usage example

   import (
	   "errors"
	   "github.com/rudderlabs/rudder-go-kit/config"
	   "github.com/rudderlabs/rudder-go-kit/logger"
   )

   var c = config.New()
   var loggerFactory = logger.NewFactory(c)
   var log logger.Logger = loggerFactory.NewLogger()
   ...
   log.Error(...)

or if you want to use the default logger factory (not advised):

var log logger.Logger = logger.NewLogger()
...
log.Error(...)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Expand added in v0.18.0

func Expand(fields ...Field) []any

Expand is useful if you want to use the type Field with the sugared logger e.g. l.Infow("my message", logger.Expand(f1, f2, f3)...)

func GetLoggingConfig

func GetLoggingConfig() map[string]int

GetLoggingConfig returns the log levels for default logger factory

func Reset

func Reset()

Reset resets the default logger factory. Shall only be used by tests, until we move to a proper DI framework

func SetLogLevel

func SetLogLevel(name, levelStr string) error

SetLogLevel sets the log level for a module for the default logger factory

func Sync

func Sync()

Sync flushes the loggers' output buffers for the default logger factory

Types

type Factory

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

Factory is a factory for creating new loggers

var Default *Factory

Default factory instance

func NewFactory

func NewFactory(config *config.Config, options ...Option) *Factory

NewFactory creates a new logger factory

func (*Factory) GetLoggingConfig

func (f *Factory) GetLoggingConfig() map[string]int

GetLoggingConfig returns the log levels

func (*Factory) NewLogger

func (f *Factory) NewLogger() Logger

NewLogger creates a new logger

func (*Factory) SetLogLevel

func (f *Factory) SetLogLevel(name, levelStr string) error

SetLogLevel sets the log level for a module

func (*Factory) Sync

func (f *Factory) Sync()

Sync flushes the loggers' output buffers

type Field added in v0.18.0

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

func NewBoolField added in v0.18.0

func NewBoolField(key string, v bool) Field

func NewDurationField added in v0.18.0

func NewDurationField(key string, v time.Duration) Field

func NewErrorField added in v0.18.0

func NewErrorField(v error) Field

func NewField added in v0.18.0

func NewField(key string, v any) Field

func NewFloatField added in v0.18.0

func NewFloatField(key string, v float64) Field

func NewIntField added in v0.18.0

func NewIntField(key string, v int64) Field

func NewStringField added in v0.18.0

func NewStringField(key, v string) Field

func NewTimeField added in v0.18.0

func NewTimeField(key string, v time.Time) Field

func (Field) Name added in v0.18.0

func (f Field) Name() string

func (Field) Value added in v0.18.0

func (f Field) Value() any

type FieldType added in v0.18.0

type FieldType uint8
const (
	UnknownType FieldType = iota
	StringType
	IntType
	BoolType
	FloatType
	TimeType
	DurationType
	ErrorType
)

type Logger

type Logger interface {
	// IsDebugLevel Returns true is debug lvl is enabled
	IsDebugLevel() bool

	// Debug level logging. Most verbose logging level.
	Debug(args ...any)

	// Debugf does debug level logging similar to fmt.Printf. Most verbose logging level
	Debugf(format string, args ...any)

	// Debugw does debug level structured logging. Most verbose logging level
	Debugw(msg string, keysAndValues ...any)

	// Debugn does debug level non-sugared structured logging. Most verbose logging level
	Debugn(msg string, fields ...Field)

	// Info level logging. Use this to log the state of the application.
	// Don't use Logger.Info in the flow of individual events. Use Logger.Debug instead.
	Info(args ...any)

	// Infof does info level logging similar to fmt.Printf. Use this to log the state of the application.
	// Don't use Logger.Info in the flow of individual events. Use Logger.Debug instead.
	Infof(format string, args ...any)

	// Infow does info level structured logging. Use this to log the state of the application.
	// Don't use Logger.Info in the flow of individual events. Use Logger.Debug instead.
	Infow(msg string, keysAndValues ...any)

	// Infon does info level non-sugared structured logging. Use this to log the state of the application.
	// Don't use Logger.Info in the flow of individual events. Use Logger.Debug instead.
	Infon(msg string, fields ...Field)

	// Warn level logging. Use this to log warnings
	Warn(args ...any)

	// Warnf does warn level logging similar to fmt.Printf. Use this to log warnings
	Warnf(format string, args ...any)

	// Warnw does warn level structured logging. Use this to log warnings
	Warnw(msg string, keysAndValues ...any)

	// Warnn does warn level non-sugared structured logging. Use this to log warnings
	Warnn(msg string, fields ...Field)

	// Error level logging. Use this to log errors which don't immediately halt the application.
	Error(args ...any)

	// Errorf does error level logging similar to fmt.Printf. Use this to log errors which don't immediately halt the application.
	Errorf(format string, args ...any)

	// Errorw does error level structured logging.
	// Use this to log errors which don't immediately halt the application.
	Errorw(msg string, keysAndValues ...any)

	// Errorn does error level non-sugared structured logging.
	// Use this to log errors which don't immediately halt the application.
	Errorn(msg string, fields ...Field)

	// Fatal level logging. Use this to log errors which crash the application.
	Fatal(args ...any)

	// Fatalf does fatal level logging similar to fmt.Printf. Use this to log errors which crash the application.
	Fatalf(format string, args ...any)

	// Fatalw does fatal level structured logging.
	// Use this to log errors which crash the application.
	Fatalw(format string, keysAndValues ...any)

	// Fataln does fatal level non-sugared structured logging.
	// Use this to log errors which crash the application.
	Fataln(format string, fields ...Field)

	LogRequest(req *http.Request)

	// Child creates a child logger with the given name
	Child(s string) Logger

	// With adds the provided key value pairs to the logger context
	With(args ...any) Logger

	// Withn adds the provided key value pairs to the logger context
	Withn(args ...Field) Logger
}
var NOP Logger = nop{}

func NewLogger

func NewLogger() Logger

NewLogger creates a new logger using the default logger factory

type Option

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

An Option configures a Factory.

func WithClock

func WithClock(clock zapcore.Clock) Option

WithClock specifies the clock used by the logger to determine the current time for logged entries. Defaults to the system clock with time.Now.

Directories

Path Synopsis
Package mock_logger is a generated GoMock package.
Package mock_logger is a generated GoMock package.

Jump to

Keyboard shortcuts

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