gologger

package
v1.11.1-beta.2 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: MIT Imports: 11 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 log debug messages

func (*CustomLogger) LogDebugWithContext added in v1.10.0

func (l *CustomLogger) LogDebugWithContext(ctx context.Context, str string)

LogDebugWithContext is used to log debug messages. It will also add trace_id and span_id in the log if it exists in the context

func (*CustomLogger) LogDebugf

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

LogDebugf is used to log debug messages

func (*CustomLogger) LogDebugfWithContext added in v1.10.0

func (l *CustomLogger) LogDebugfWithContext(ctx context.Context, str string, args ...interface{})

LogDebugfWithContext is used to log debug messages with any interface type. It will also add trace_id and span_id in the log if it exists in the context

func (*CustomLogger) LogError

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

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

func (*CustomLogger) LogErrorInterface

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

LogErrorInterface is used to log errors

func (*CustomLogger) LogErrorMessage

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

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

func (*CustomLogger) LogErrorWithContext added in v1.10.0

func (l *CustomLogger) LogErrorWithContext(ctx context.Context, str string, err error)

LogErrorWithContext is used to log errors and a message along with the error It will also add trace_id and span_id in the log if it exists in the context.

func (*CustomLogger) LogErrorWithoutError

func (l *CustomLogger) LogErrorWithoutError(str string)

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

func (*CustomLogger) LogErrorWithoutErrorf

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

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

func (*CustomLogger) LogErrorfWithContext added in v1.10.0

func (l *CustomLogger) LogErrorfWithContext(ctx context.Context, str string, err error, args ...interface{})

LogErrorfWithContext is used to log errors, a message and interface of any type along with the error It will also add trace_id and span_id in the log if it exists in the context.

func (*CustomLogger) LogInfo

func (l *CustomLogger) LogInfo(str string)

LogInfo is used to log info messages

func (*CustomLogger) LogInfoMessage

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

LogInfoMessage is used to log extra fields to graylog

func (*CustomLogger) LogInfoWithContext added in v1.10.0

func (l *CustomLogger) LogInfoWithContext(ctx context.Context, str string)

LogInfoWithContext is used to log info messages. It will also add trace_id and span_id in the log if it exists in the context.

func (*CustomLogger) LogInfof

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

LogInfof is used to log formatted info messages

func (*CustomLogger) LogInfofWithContext added in v1.10.0

func (l *CustomLogger) LogInfofWithContext(ctx context.Context, str string, args ...interface{})

LogInfofWithContext is used to log info messages with any interface type. It will also add trace_id and span_id in the log if it exists in the context.

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 log warning messages

func (*CustomLogger) LogWarningMessage

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

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

func (*CustomLogger) LogWarningWithContext added in v1.10.0

func (l *CustomLogger) LogWarningWithContext(ctx context.Context, str string)

LogWarningWithContext is used to log warning messages. It will also add trace_id and span_id in the log if it exists in the context.

func (*CustomLogger) LogWarningf

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

LogWarningf is used to log warning messages

func (*CustomLogger) LogWarningfWithContext added in v1.10.0

func (l *CustomLogger) LogWarningfWithContext(ctx context.Context, str string, args ...interface{})

LogWarningfWithContext is used to log warning messages with any interface type. It will also add trace_id and span_id in the log if it exists in the context.

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