gologger

package
v1.9.5-beta2 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CounterMetric

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

CounterMetric : Default histogram message type implementing IMetricVec

func NewCounterMetric

func NewCounterMetric(counter *prometheus.CounterVec, logger *CustomLogger) *CounterMetric

NewCounterMetric creates a new histrogram message and registers it to prometheus

func (*CounterMetric) AddValue

func (msg *CounterMetric) AddValue(count int64, labels ...string)

AddValue will increment the counter by value

func (*CounterMetric) RemoveLogging

func (msg *CounterMetric) RemoveLogging(labels ...string)

RemoveLogging will stop logging for specific labels

func (*CounterMetric) SetValue

func (msg *CounterMetric) SetValue(count int64, labels ...string)

SetValue will not do anything. It is not allowed in counters

func (*CounterMetric) SubValue

func (msg *CounterMetric) SubValue(count int64, labels ...string)

SubValue will not do anything. It is not allowed in counters

func (*CounterMetric) UpdateTime

func (msg *CounterMetric) UpdateTime(elapsed int64, labels ...string)

UpdateTime is a do nothing operation for counter metric

type CustomLogger

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

CustomLogger is a graylog logger for golang

func NewLogger

func NewLogger(LoggerOptions ...Option) *CustomLogger

NewLogger : returns a new logger. When no options are given, it returns an error logger With graylog logging as default to a port 11100 which is not in use. So it is prety much useless. Please provide graylog host and port at the very least.

func (*CustomLogger) GetLogLevel

func (l *CustomLogger) GetLogLevel() LogLevels

GetLogLevel is used to get the current Log level

func (*CustomLogger) LogDebug

func (l *CustomLogger) LogDebug(str string)

LogDebug is used to send debug messages

func (*CustomLogger) LogDebugf

func (l *CustomLogger) LogDebugf(str string, args ...interface{})

LogDebugf is used to send debug messages

func (*CustomLogger) LogError

func (l *CustomLogger) LogError(str string, err error)

LogError is used to send errors and a message along with the error

func (*CustomLogger) LogErrorInterface

func (l *CustomLogger) LogErrorInterface(v ...interface{})

LogErrorInterface is used to send errors

func (*CustomLogger) LogErrorMessage

func (l *CustomLogger) LogErrorMessage(str string, err error, pairs ...Pair)

LogErrorMessage is used to send extra fields to graylog along with the error

func (*CustomLogger) LogErrorWithoutError

func (l *CustomLogger) LogErrorWithoutError(str string)

LogErrorWithoutError is used to send only a message and not an error

func (*CustomLogger) LogErrorWithoutErrorf

func (l *CustomLogger) LogErrorWithoutErrorf(str string, args ...interface{})

LogErrorWithoutErrorf is used to send only a message and not an error

func (*CustomLogger) LogInfo

func (l *CustomLogger) LogInfo(str string)

LogInfo is used to send info messages

func (*CustomLogger) LogInfoMessage

func (l *CustomLogger) LogInfoMessage(str string, pairs ...Pair)

LogInfoMessage is used to send extra fields to graylog

func (*CustomLogger) LogInfof

func (l *CustomLogger) LogInfof(str string, args ...interface{})

LogInfof is used to send formatted info messages

func (*CustomLogger) LogMessage

func (l *CustomLogger) LogMessage(message string)

LogMessage is used to log plain message

func (*CustomLogger) LogMessageWithExtras

func (l *CustomLogger) LogMessageWithExtras(message string, level LogLevels, pairs ...Pair)

func (*CustomLogger) LogMessagef

func (l *CustomLogger) LogMessagef(message string, args ...interface{})

LogMessagef is used to log plain message

func (*CustomLogger) LogWarning

func (l *CustomLogger) LogWarning(str string)

LogWarning is used to send warning messages

func (*CustomLogger) LogWarningMessage

func (l *CustomLogger) LogWarningMessage(str string, pairs ...Pair)

LogWarningMessage is used to send warning messages along with extra fields to GrayLog

func (*CustomLogger) LogWarningf

func (l *CustomLogger) LogWarningf(str string, args ...interface{})

LogWarningf is used to send warning messages

func (*CustomLogger) Tic

func (l *CustomLogger) Tic(s string) (string, time.Time)

Tic is used to log time taken by a function. It should be used along with Toc function Tic will take an input as a string message (It can be the name of the function) And will return time and the message. For full used see the Toc funtion

func (*CustomLogger) Toc

func (l *CustomLogger) Toc(message string, startTime time.Time)

Toc will log the time taken by the funtion. Its input is the output of the Tic function Here is an example code block for using Tic and Toc function

defer Toc(Tic("FunctionName"))

This will the first line of the function

type GaugeMetric

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

GaugeMetric : Default Gauge message type implementing IMetricVec

func NewGaugeMetric

func NewGaugeMetric(counter *prometheus.GaugeVec, logger *CustomLogger) *GaugeMetric

NewGaugeMetric creates a new gauge message and registers it to prometheus

func (*GaugeMetric) AddValue

func (msg *GaugeMetric) AddValue(count int64, labels ...string)

AddValue will increment the counter by value

func (*GaugeMetric) RemoveLogging

func (msg *GaugeMetric) RemoveLogging(labels ...string)

RemoveLogging will stop logging for specific labels

func (*GaugeMetric) SetValue

func (msg *GaugeMetric) SetValue(count int64, labels ...string)

SetValue will set the counter to that value

func (*GaugeMetric) SubValue

func (msg *GaugeMetric) SubValue(count int64, labels ...string)

SubValue will decrement the counter by value

func (*GaugeMetric) UpdateTime

func (msg *GaugeMetric) UpdateTime(elapsed int64, labels ...string)

UpdateTime is a do nothing operation for counter metric

type HistogramMetric

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

HistogramMetric : Default histogram message type implementing IMetricVec

func NewHistogramMetric

func NewHistogramMetric(hist *prometheus.HistogramVec, logger *CustomLogger) *HistogramMetric

NewHistogramMetric creates a new histrogram message and registers it to prometheus

func (*HistogramMetric) AddValue

func (msg *HistogramMetric) AddValue(count int64, labels ...string)

AddValue is a do nothing function for histogram

func (*HistogramMetric) RemoveLogging

func (msg *HistogramMetric) RemoveLogging(labels ...string)

RemoveLogging will stop logging for specific labels

func (*HistogramMetric) SetValue

func (msg *HistogramMetric) SetValue(count int64, labels ...string)

SetValue is a do nothing function for histogram

func (*HistogramMetric) SubValue

func (msg *HistogramMetric) SubValue(count int64, labels ...string)

SubValue is a do nothing function for histogram

func (*HistogramMetric) UpdateTime

func (msg *HistogramMetric) UpdateTime(elapsed int64, labels ...string)

UpdateTime the message with calculated latency

type IMetricVec

type IMetricVec interface {
	UpdateTime(int64, ...string)
	//Method to count increments or gauges
	AddValue(int64, ...string)
	// Method to subtract from the counter
	SubValue(int64, ...string)
	// Method to set the counter
	SetValue(int64, ...string)
	// Method to Remove the label from the metric
	RemoveLogging(...string)
}

IMetricVec : Interface to implement for Message type

type IMultiLogger

type IMultiLogger interface {
	// To measure time elapsed between any two points in the code,
	// Start the time logger by Tic(MessageDesc) and end the time logger by calling Toc(MessageDesc,time)
	Tic() time.Time
	Toc(time.Time, string, ...string)
	IncVal(int64, string, ...string)
	SubVal(int64, string, ...string)
	SetVal(int64, string, ...string)
	AddNewMetric(string, IMetricVec)
}

IMultiLogger : Interface for Multi message logger

func NewRateLatencyLogger

func NewRateLatencyLogger(options ...RateLatencyOption) IMultiLogger

NewRateLatencyLogger : returns a new RateLatencyLogger. When no options are given, it returns a RateLatencyLogger with default settings. Default logger is default custom logger.

type LogLevels

type LogLevels uint32

LogLevels are the log levels for logging

const (
	// ERROR : All errors will be logged with this level
	ERROR LogLevels = 0

	// WARN : All important events should be logged with a warn
	WARN LogLevels = 1

	// INFO : All events other than the important ones to be logged here
	INFO LogLevels = 2

	// DEBUG : This is for debug purposes only. Never use it on staging and production
	DEBUG LogLevels = 3
)

func (LogLevels) String

func (i LogLevels) String() string

type Option

type Option func(l *CustomLogger)

Option sets a parameter for the Logger

func ConsolePrintEnabled

func ConsolePrintEnabled(flag bool) Option

ConsolePrintEnabled enables console output for logging. To be used only for development.

func DisableGraylog

func DisableGraylog(flag bool) Option

DisableGraylog disables graylog logging. Defaults to false If graylog is disabled console logging will be enabled by default

func GraylogFacility

func GraylogFacility(facility string) Option

GraylogFacility sets the graylog facility for the logger. Default is "ErrorLogger"

func GraylogHost

func GraylogHost(hostName string) Option

GraylogHost sets the graylog host for the logger. Default is 127.0.0.1

func GraylogPort

func GraylogPort(portNumber int) Option

GraylogPort sets the graylog port for the logger. Default is 11100

func SetK8sNamespace added in v1.1.0

func SetK8sNamespace(k8sNamespace string) Option

K8sNamespace sets the graylog k8sNamespace for the logger. Default is "dev" This option will have no effect if env variable K8S_NAMESPACE is set

func SetLogLevel

func SetLogLevel(level string) Option

SetLogLevel sets the logger level Possible values are ERROR, WARN, INFO, DEBUG. Default is ERROR

func TimeLoggingEnabled

func TimeLoggingEnabled(flag bool) Option

TimeLoggingEnabled enables logging of time (The use of tic toc functions). This can be used in functions and then disabled here when there is no need.

type Pair

type Pair struct {
	Key, Value string
}

Pair is a tuple of strings

type RateLatencyLogger

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

RateLatencyLogger : Logger that tracks multiple messages & prints to console

func (*RateLatencyLogger) AddNewMetric

func (mgl *RateLatencyLogger) AddNewMetric(messageIdentifier string, newMessage IMetricVec)

AddNewMetric sets New message initialisation function

func (*RateLatencyLogger) IncVal

func (mgl *RateLatencyLogger) IncVal(value int64, identifier string, labels ...string)

IncVal is used for counters and gauges

func (*RateLatencyLogger) SetVal

func (mgl *RateLatencyLogger) SetVal(value int64, identifier string, labels ...string)

SetVal is used for counters and gauges

func (*RateLatencyLogger) SubVal

func (mgl *RateLatencyLogger) SubVal(value int64, identifier string, labels ...string)

SubVal is used for counters and gauges

func (*RateLatencyLogger) Tic

func (mgl *RateLatencyLogger) Tic() time.Time

Tic starts the timer

func (*RateLatencyLogger) Toc

func (mgl *RateLatencyLogger) Toc(start time.Time, identifier string, labels ...string)

Toc calculates the time elapsed since Tic() and stores in the Message

type RateLatencyOption

type RateLatencyOption func(rl *RateLatencyLogger)

RateLatencyOption sets a parameter for the RateLatencyLogger

func SetLogger

func SetLogger(logger *CustomLogger) RateLatencyOption

SetLogger sets the output logger. Default is stderr

Jump to

Keyboard shortcuts

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