logger

package
v0.16.3 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: AGPL-3.0 Imports: 12 Imported by: 112

Documentation

Overview

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 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 Logger

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

	// Debug level logging. Most verbose logging level.
	Debug(args ...interface{})

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

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

	// Info level logging. Use this to log the state of the application. Dont use Logger.Info in the flow of individual events. Use Logger.Debug instead.
	Info(args ...interface{})

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

	// Infof does info level structured logging. Use this to log the state of the application. Dont use Logger.Info in the flow of individual events. Use Logger.Debug instead.
	Infow(msg string, keysAndValues ...interface{})

	// Warn level logging. Use this to log warnings
	Warn(args ...interface{})

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

	// Warnf does warn level structured logging. Use this to log warnings
	Warnw(msg string, keysAndValues ...interface{})

	// Error level logging. Use this to log errors which dont immediately halt the application.
	Error(args ...interface{})

	// Errorf does error level logging similar to fmt.Printf. Use this to log errors which dont immediately halt the application.
	Errorf(format string, args ...interface{})

	// Errorf does error level structured logging. Use this to log errors which dont immediately halt the application.
	Errorw(msg string, keysAndValues ...interface{})

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

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

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

	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 ...interface{}) 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