logger

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2023 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Logger Interface Use instance of logger instead of exported functions

usage example

   import (
	   "errors"
	   "github.com/rudderlabs/rudder-server/config"
	   "github.com/rudderlabs/rudder-server/utils/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 added in v0.1.10

func GetLoggingConfig() map[string]int

GetLoggingConfig returns the log levels for default logger factory

func Reset added in v1.2.0

func Reset()

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

func SetLogLevel added in v1.2.0

func SetLogLevel(name, levelStr string) error

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

func Sync added in v1.2.0

func Sync()

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

Types

type Factory added in v1.2.0

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

Factory is a factory for creating new loggers

var Default *Factory

default factory instance

func NewFactory added in v1.2.0

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

NewFactory creates a new logger factory

func (*Factory) GetLoggingConfig added in v1.2.0

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

GetLoggingConfig returns the log levels

func (*Factory) NewLogger added in v1.2.0

func (f *Factory) NewLogger() Logger

NewLogger creates a new logger

func (*Factory) SetLogLevel added in v1.2.0

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

SetLogLevel sets the log level for a module

func (*Factory) Sync added in v1.2.0

func (f *Factory) Sync()

Sync flushes the loggers' output buffers

type Logger added in v1.2.0

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 added in v0.1.10

func NewLogger() Logger

NewLogger creates a new logger using the default logger factory

type Option added in v1.2.0

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

An Option configures a Factory.

func WithClock added in v1.2.0

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.

Jump to

Keyboard shortcuts

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