gologger

package
v2.1.3-beta.1+incompat... Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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) 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) 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 IMessage

type IMessage interface {
	Update(int64)
	// Method to Jsonify the message struct
	Jsonify() string
	// Method to Reset the message struct
	Reset()
}

IMessage : Interface to implement for Message type

func NewMessage

func NewMessage(module string) IMessage

NewMessage returns default message instance

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(string) time.Time
	Toc(string, time.Time)
	// Method to push the message to respective output stream (Console, Graylog, etc..)
	Push()
	// Starts the logger in a go routine
	Run()
}

IMultiLogger : Interface for Multi message logger

func NewMultiGoLogger

func NewMultiGoLogger(interval int, modules []string) IMultiLogger

NewMultiGoLogger initialises the RateLatencyLogger. This will be removed in next revision. Use NewRateLatencyLogger instead.

func NewMultiGrayLogger

func NewMultiGrayLogger(host string, port int, interval int, modules []string) IMultiLogger

NewMultiGrayLogger initialises the MultiGrayLogger. This will be removed in next revision. Use NewRateLatencyLogger instead.

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. NOTE: Be sure to SetNewMessage before setting option SetMessages.

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 Message

type Message struct {
	Requests     int64
	TotalLatency int64
	MaxLatency   int64
	MinLatency   int64
	Module       string // Module name
}

Message : Default message type implementing IMessage

func (*Message) Jsonify

func (msg *Message) Jsonify() string

Jsonify : method to Jsonify the message struct

func (*Message) Reset

func (msg *Message) Reset()

Reset : Method to Reset the message struct

func (*Message) Update

func (msg *Message) Update(elapsed int64)

Update the message with calculated latency

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 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) Push

func (mgl *RateLatencyLogger) Push()

Push : Method to push the message to respective output stream (Console)

func (*RateLatencyLogger) Run

func (mgl *RateLatencyLogger) Run()

Run : Starts the logger in a go routine. Calling this multiple times doesn't have any effect

func (*RateLatencyLogger) Tic

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

Tic starts the timer

func (*RateLatencyLogger) Toc

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

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 SetInterval

func SetInterval(interval int) RateLatencyOption

SetInterval sets the time interval to push the message. interval in seconds. Default is 60 seconds.

func SetLogger

func SetLogger(logger *CustomLogger) RateLatencyOption

SetLogger sets the output logger. Default is stderr

func SetMessages

func SetMessages(modules []string) RateLatencyOption

SetMessages sets messages map

func SetNewMessage

func SetNewMessage(newMessage func(string) IMessage) RateLatencyOption

SetNewMessage sets New message initialisation function

Jump to

Keyboard shortcuts

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