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 ¶
- func Expand(fields ...Field) []any
- func GetLoggingConfig() map[string]int
- func Reset()
- func SetLogLevel(name, levelStr string) error
- func Sync()
- type Factory
- type Field
- func NewBoolField(key string, v bool) Field
- func NewDurationField(key string, v time.Duration) Field
- func NewErrorField(v error) Field
- func NewField(key string, v any) Field
- func NewFloatField(key string, v float64) Field
- func NewIntField(key string, v int64) Field
- func NewStringField(key, v string) Field
- func NewTimeField(key string, v time.Time) Field
- type FieldType
- type Logger
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Expand ¶ added in v0.18.0
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 ¶
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 ¶
SetLogLevel sets the log level for a module 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 ¶
NewFactory creates a new logger factory
func (*Factory) GetLoggingConfig ¶
GetLoggingConfig returns the log levels
func (*Factory) SetLogLevel ¶
SetLogLevel sets the log level for a module
type Field ¶ added in v0.18.0
type Field struct {
// contains filtered or unexported fields
}
func NewBoolField ¶ added in v0.18.0
func NewErrorField ¶ added in v0.18.0
func NewFloatField ¶ added in v0.18.0
func NewIntField ¶ added in v0.18.0
func NewStringField ¶ added in v0.18.0
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{}
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package mock_logger is a generated GoMock package.
|
Package mock_logger is a generated GoMock package. |