logger

package
v6.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2016 License: Apache-2.0 Imports: 7 Imported by: 105

README

logger

-- import "gopkg.in/Clever/kayvee-go.v6/logger"

Usage

type Formatter
type Formatter func(data map[string]interface{}) string

Formatter is a function type that takes a map and returns a formatted string with the contents of the map

type LogLevel
type LogLevel int

LogLevel is an enum is used to denote level of logging

const (
	Debug LogLevel = iota
	Info
	Warning
	Error
	Critical
)

Constants used to define different LogLevels supported

func (LogLevel) String
func (l LogLevel) String() string
type Logger
type Logger struct {
}

Logger provides customization of log messages. We can change globals, default log level, formatting, and output destination.

func New
func New(source string) *Logger

New creates a *logger.Logger. Default values are Debug LogLevel, kayvee Formatter, and std.err output.

func (*Logger) Counter
func (l *Logger) Counter(title string)

Counter takes a string and logs with LogLevel = Info, type = counter, and value = 1

func (*Logger) CounterD
func (l *Logger) CounterD(title string, value int, data map[string]interface{})

CounterD takes a string, value, and data map. It logs with LogLevel = Info, type = counter, and value = value

func (*Logger) Critical
func (l *Logger) Critical(title string)

Critical takes a string and logs with LogLevel = Critical

func (*Logger) CriticalD
func (l *Logger) CriticalD(title string, data map[string]interface{})

CriticalD takes a string and data map. It logs with LogLevel = Critical

func (*Logger) Debug
func (l *Logger) Debug(title string)

Debug takes a string and logs with LogLevel = Debug

func (*Logger) DebugD
func (l *Logger) DebugD(title string, data map[string]interface{})

DebugD takes a string and data map. It logs with LogLevel = Debug

func (*Logger) Error
func (l *Logger) Error(title string)

Error takes a string and logs with LogLevel = Error

func (*Logger) ErrorD
func (l *Logger) ErrorD(title string, data map[string]interface{})

ErrorD takes a string and data map. It logs with LogLevel = Error

func (*Logger) GaugeFloat
func (l *Logger) GaugeFloat(title string, value float64)

GaugeFloat takes a string and float value. It logs with LogLevel = Info, type = gauge, and value = value

func (*Logger) GaugeFloatD
func (l *Logger) GaugeFloatD(title string, value float64, data map[string]interface{})

GaugeFloatD takes a string, a float value, and data map. It logs with LogLevel = Info, type = gauge, and value = value

func (*Logger) GaugeInt
func (l *Logger) GaugeInt(title string, value int)

GaugeInt takes a string and integer value. It logs with LogLevel = Info, type = gauge, and value = value

func (*Logger) GaugeIntD
func (l *Logger) GaugeIntD(title string, value int, data map[string]interface{})

GaugeIntD takes a string, an integer value, and data map. It logs with LogLevel = Info, type = gauge, and value = value

func (*Logger) Info
func (l *Logger) Info(title string)

Info takes a string and logs with LogLevel = Info

func (*Logger) InfoD
func (l *Logger) InfoD(title string, data map[string]interface{})

InfoD takes a string and data map. It logs with LogLevel = Info

func (*Logger) SetConfig
func (l *Logger) SetConfig(source string, logLvl LogLevel, formatter Formatter, output io.Writer)

SetConfig allows configuration changes in one go

func (*Logger) SetFormatter
func (l *Logger) SetFormatter(formatter Formatter)

SetFormatter sets the formatter function to use

func (*Logger) SetLogLevel
func (l *Logger) SetLogLevel(logLvl LogLevel)

SetLogLevel sets the default log level threshold

func (*Logger) SetOutput
func (l *Logger) SetOutput(output io.Writer)

SetOutput changes the output destination of the logger

func (*Logger) Warn
func (l *Logger) Warn(title string)

Warn takes a string and logs with LogLevel = Warning

func (*Logger) WarnD
func (l *Logger) WarnD(title string, data map[string]interface{})

WarnD takes a string and data map. It logs with LogLevel = Warning

type M
type M map[string]interface{}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, logger KayveeLogger) context.Context

NewContext creates a new context object containing a logger value.

func SetGlobalRouting

func SetGlobalRouting(filename string) error

SetGlobalRouting installs a new log router onto the KayveeLogger with the configuration specified in `filename`. For convenience, the KayveeLogger is expected to return itself as the first return value.

Types

type Formatter

type Formatter func(data map[string]interface{}) string

Formatter is a function type that takes a map and returns a formatted string with the contents of the map

type KayveeLogger

type KayveeLogger interface {

	// AddContext adds a new key-val to be logged with all log messages.
	AddContext(key, val string)

	// SetConfig allows configuration changes in one go
	SetConfig(source string, logLvl LogLevel, formatter Formatter, output io.Writer)

	// SetFormatter sets the formatter function to use
	SetFormatter(formatter Formatter)

	// SetLogLevel sets the default log level threshold
	SetLogLevel(logLvl LogLevel)

	// SetOutput changes the output destination of the logger
	SetOutput(output io.Writer)

	// SetRouter changes the router for this logger instance.  Once set, logs produced by this
	// logger will not be touched by the global router.  Mostly used for testing and benchmarking.
	SetRouter(router router.Router)

	// Counter takes a string and logs with LogLevel = Info
	Counter(title string)

	// CounterD takes a string, value, and data map. It logs with LogLevel = Info
	CounterD(title string, value int, data map[string]interface{})

	// Critical takes a string and logs with LogLevel = Critical
	Critical(title string)

	// CriticalD takes a string and data map. It logs with LogLevel = Critical
	CriticalD(title string, data map[string]interface{})

	// Debug takes a string and logs with LogLevel = Debug
	Debug(title string)

	// DebugD takes a string and data map. It logs with LogLevel = Debug
	DebugD(title string, data map[string]interface{})

	// Error takes a string and logs with LogLevel = Error
	Error(title string)

	// ErrorD takes a string and data map. It logs with LogLevel = Error
	ErrorD(title string, data map[string]interface{})

	// GaugeFloat takes a string and float value. It logs with LogLevel = Info
	GaugeFloat(title string, value float64)

	// GaugeFloatD takes a string, a float value, and data map. It logs with LogLevel = Info
	GaugeFloatD(title string, value float64, data map[string]interface{})

	// GaugeInt takes a string and integer value. It logs with LogLevel = Info
	GaugeInt(title string, value int)

	// GaugeIntD takes a string, an integer value, and data map. It logs with LogLevel = Info
	GaugeIntD(title string, value int, data map[string]interface{})

	// Info takes a string and logs with LogLevel = Info
	Info(title string)

	// InfoD takes a string and data map. It logs with LogLevel = Info
	InfoD(title string, data map[string]interface{})

	// Warn takes a string and logs with LogLevel = Warning
	Warn(title string)

	// WarnD takes a string and data map. It logs with LogLevel = Warning
	WarnD(title string, data map[string]interface{})
	// contains filtered or unexported methods
}

KayveeLogger is the main logging interface, providing customization of log messages.

func FromContext

func FromContext(ctx context.Context) KayveeLogger

FromContext returns the logger value contained in a context. For convenience, if the context does not contain a logger, a new logger is created and returned. This allows users of this method to use the logger immediately, e.g.

logger.FromContext(ctx).Info("...")

func New

func New(source string) KayveeLogger

New creates a *logger.Logger. Default values are Debug LogLevel, kayvee Formatter, and std.err output.

func NewWithContext

func NewWithContext(source string, contextValues map[string]interface{}) KayveeLogger

NewWithContext creates a *logger.Logger. Default values are Debug LogLevel, kayvee Formatter, and std.err output.

type LogLevel

type LogLevel int

LogLevel is an enum is used to denote level of logging

const (
	Debug LogLevel = iota
	Info
	Warning
	Error
	Critical
)

Constants used to define different LogLevels supported

func (LogLevel) String

func (l LogLevel) String() string

type Logger

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

Logger is the default implementation of KayveeLogger. It provides customization of globals, default log level, formatting, and output destination.

func (*Logger) AddContext

func (l *Logger) AddContext(key, val string)

AddContext implements the method for the KayveeLogger interface.

func (*Logger) Counter

func (l *Logger) Counter(title string)

Counter implements the method for the KayveeLogger interface. Logs with type = gauge, and value = value

func (*Logger) CounterD

func (l *Logger) CounterD(title string, value int, data map[string]interface{})

CounterD implements the method for the KayveeLogger interface. Logs with type = gauge, and value = value

func (*Logger) Critical

func (l *Logger) Critical(title string)

Critical implements the method for the KayveeLogger interface.

func (*Logger) CriticalD

func (l *Logger) CriticalD(title string, data map[string]interface{})

CriticalD implements the method for the KayveeLogger interface.

func (*Logger) Debug

func (l *Logger) Debug(title string)

Debug implements the method for the KayveeLogger interface.

func (*Logger) DebugD

func (l *Logger) DebugD(title string, data map[string]interface{})

DebugD implements the method for the KayveeLogger interface.

func (*Logger) Error

func (l *Logger) Error(title string)

Error implements the method for the KayveeLogger interface.

func (*Logger) ErrorD

func (l *Logger) ErrorD(title string, data map[string]interface{})

ErrorD implements the method for the KayveeLogger interface.

func (*Logger) GaugeFloat

func (l *Logger) GaugeFloat(title string, value float64)

GaugeFloat implements the method for the KayveeLogger interface. Logs with type = gauge, and value = value

func (*Logger) GaugeFloatD

func (l *Logger) GaugeFloatD(title string, value float64, data map[string]interface{})

GaugeFloatD implements the method for the KayveeLogger interface. Logs with type = gauge, and value = value

func (*Logger) GaugeInt

func (l *Logger) GaugeInt(title string, value int)

GaugeInt implements the method for the KayveeLogger interface. Logs with type = gauge, and value = value

func (*Logger) GaugeIntD

func (l *Logger) GaugeIntD(title string, value int, data map[string]interface{})

GaugeIntD implements the method for the KayveeLogger interface. Logs with type = gauge, and value = value

func (*Logger) Info

func (l *Logger) Info(title string)

Info implements the method for the KayveeLogger interface.

func (*Logger) InfoD

func (l *Logger) InfoD(title string, data map[string]interface{})

InfoD implements the method for the KayveeLogger interface.

func (*Logger) SetConfig

func (l *Logger) SetConfig(source string, logLvl LogLevel, formatter Formatter, output io.Writer)

SetConfig implements the method for the KayveeLogger interface.

func (*Logger) SetFormatter

func (l *Logger) SetFormatter(formatter Formatter)

SetFormatter implements the method for the KayveeLogger interface.

func (*Logger) SetLogLevel

func (l *Logger) SetLogLevel(logLvl LogLevel)

SetLogLevel implements the method for the KayveeLogger interface.

func (*Logger) SetOutput

func (l *Logger) SetOutput(output io.Writer)

SetOutput implements the method for the KayveeLogger interface.

func (*Logger) SetRouter

func (l *Logger) SetRouter(router router.Router)

SetRouter implements the method for the KayveeLogger interface.

func (*Logger) Warn

func (l *Logger) Warn(title string)

Warn implements the method for the KayveeLogger interface.

func (*Logger) WarnD

func (l *Logger) WarnD(title string, data map[string]interface{})

WarnD implements the method for the KayveeLogger interface.

type M

type M map[string]interface{}

M is a convenience type for passing data into a log message.

type MockRouteCountLogger

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

MockRouteCountLogger is a mock implementation of KayveeLogger that counts the router rules applied to each log call without actually formatting or writing the log line.

func NewMockCountLogger

func NewMockCountLogger(source string) *MockRouteCountLogger

NewMockCountLogger returns a new MockRoutCountLogger with the specified `source`.

func NewMockCountLoggerWithContext

func NewMockCountLoggerWithContext(source string, contextValues map[string]interface{}) *MockRouteCountLogger

NewMockCountLoggerWithContext returns a new MockRoutCountLogger with the specified `source` and `contextValues`.

func (*MockRouteCountLogger) AddContext

func (ml *MockRouteCountLogger) AddContext(key, val string)

AddContext implements the method for the KayveeLogger interface.

func (*MockRouteCountLogger) Counter

func (ml *MockRouteCountLogger) Counter(title string)

Counter implements the method for the KayveeLogger interface.

func (*MockRouteCountLogger) CounterD

func (ml *MockRouteCountLogger) CounterD(title string, value int, data map[string]interface{})

CounterD implements the method for the KayveeLogger interface.

func (*MockRouteCountLogger) Critical

func (ml *MockRouteCountLogger) Critical(title string)

Critical implements the method for the KayveeLogger interface.

func (*MockRouteCountLogger) CriticalD

func (ml *MockRouteCountLogger) CriticalD(title string, data map[string]interface{})

CriticalD implements the method for the KayveeLogger interface.

func (*MockRouteCountLogger) Debug

func (ml *MockRouteCountLogger) Debug(title string)

Debug implements the method for the KayveeLogger interface.

func (*MockRouteCountLogger) DebugD

func (ml *MockRouteCountLogger) DebugD(title string, data map[string]interface{})

DebugD implements the method for the KayveeLogger interface.

func (*MockRouteCountLogger) Error

func (ml *MockRouteCountLogger) Error(title string)

Error implements the method for the KayveeLogger interface.

func (*MockRouteCountLogger) ErrorD

func (ml *MockRouteCountLogger) ErrorD(title string, data map[string]interface{})

ErrorD implements the method for the KayveeLogger interface.

func (*MockRouteCountLogger) GaugeFloat

func (ml *MockRouteCountLogger) GaugeFloat(title string, value float64)

GaugeFloat implements the method for the KayveeLogger interface.

func (*MockRouteCountLogger) GaugeFloatD

func (ml *MockRouteCountLogger) GaugeFloatD(title string, value float64, data map[string]interface{})

GaugeFloatD implements the method for the KayveeLogger interface. Logs with type = gauge, and value = value

func (*MockRouteCountLogger) GaugeInt

func (ml *MockRouteCountLogger) GaugeInt(title string, value int)

GaugeInt implements the method for the KayveeLogger interface.

func (*MockRouteCountLogger) GaugeIntD

func (ml *MockRouteCountLogger) GaugeIntD(title string, value int, data map[string]interface{})

GaugeIntD implements the method for the KayveeLogger interface.

func (*MockRouteCountLogger) Info

func (ml *MockRouteCountLogger) Info(title string)

Info implements the method for the KayveeLogger interface.

func (*MockRouteCountLogger) InfoD

func (ml *MockRouteCountLogger) InfoD(title string, data map[string]interface{})

InfoD implements the method for the KayveeLogger interface.

func (*MockRouteCountLogger) RuleCounts

func (ml *MockRouteCountLogger) RuleCounts() map[string]int

RuleCounts returns a map of rule names to the number of times that rule has been applied in routing logs for MockRouteCountLogger. Only includes routing rules that have at least one use.

func (*MockRouteCountLogger) SetConfig

func (ml *MockRouteCountLogger) SetConfig(source string, logLvl LogLevel, formatter Formatter, output io.Writer)

SetConfig implements the method for the KayveeLogger interface.

func (*MockRouteCountLogger) SetFormatter

func (ml *MockRouteCountLogger) SetFormatter(formatter Formatter)

SetFormatter implements the method for the KayveeLogger interface.

func (*MockRouteCountLogger) SetLogLevel

func (ml *MockRouteCountLogger) SetLogLevel(logLvl LogLevel)

SetLogLevel implements the method for the KayveeLogger interface.

func (*MockRouteCountLogger) SetOutput

func (ml *MockRouteCountLogger) SetOutput(output io.Writer)

SetOutput implements the method for the KayveeLogger interface.

func (*MockRouteCountLogger) SetRouter

func (ml *MockRouteCountLogger) SetRouter(router router.Router)

SetRouter implements the method for the KayveeLogger interface.

func (*MockRouteCountLogger) Warn

func (ml *MockRouteCountLogger) Warn(title string)

Warn implements the method for the KayveeLogger interface.

func (*MockRouteCountLogger) WarnD

func (ml *MockRouteCountLogger) WarnD(title string, data map[string]interface{})

WarnD implements the method for the KayveeLogger interface.

Jump to

Keyboard shortcuts

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