logger

package
v0.0.0-...-f6de6f3 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2015 License: MIT Imports: 7 Imported by: 0

README

go-commons/logger

Common library for logging which stores the logs in elasticsearch to be accessable through kibana. The logs are stored in JSON format with the @timestamp field automatically set to the invocation time.

Sample usage:

//Init the logger and set application name and minimum log level with which messages will be stored
err := InitLogger("My application name", LOG_LEVEL_DEBUG)
if err != nil {
    panic(err)
}

//Global function to get the logger after it has been initialized. The logger is thread safe.
logger := GetLogger()

//Simple message logging
logger.Debug("debug message") //This will create a JSON with the @message field set to the passed argument and @severity to debug
logger.Info("info message") //This will create a JSON with the @message field set to the passed argument and @severity to info

//Custom map logging - allows more control over fields being stored in the JSON object
errorMap := make(map[string]interface{})
errorMap["testField"] = "testValue"
logger.ErrorMap(errorMap) //This will create a JSON with the @testField set to "testValue"

Documentation

Index

Constants

View Source
const (
	LogLevelError = iota
	LogLevelWarn  = iota
	LogLevelInfo  = iota
	LogLevelDebug = iota
)

Variables

This section is empty.

Functions

func InitLogger

func InitLogger(appName string, logLevel int) error

Should be called before using the logger - sets the app name and minimum log level of messages that should be handled

Types

type LogConsumer

type LogConsumer interface {
	Log(data string, logLevel int)
}

Enables defining additional log handlers, mainly used for unit tests

type Logger

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

Main logger structure

func GetLogger

func GetLogger() *Logger

func (*Logger) AddLogConsumer

func (logger *Logger) AddLogConsumer(logConsumer LogConsumer)

func (*Logger) Debug

func (logger *Logger) Debug(message string)

func (*Logger) DebugMap

func (logger *Logger) DebugMap(entry map[string]interface{})

func (*Logger) Error

func (logger *Logger) Error(message string)

func (*Logger) ErrorErr

func (logger *Logger) ErrorErr(err error)

func (*Logger) ErrorMap

func (logger *Logger) ErrorMap(entry map[string]interface{})

func (*Logger) Info

func (logger *Logger) Info(message string)

func (*Logger) InfoMap

func (logger *Logger) InfoMap(entry map[string]interface{})

func (*Logger) Warn

func (logger *Logger) Warn(message string)

func (*Logger) WarnMap

func (logger *Logger) WarnMap(entry map[string]interface{})

Jump to

Keyboard shortcuts

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