logger

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LevelError = iota
	LevelInfo
	LevelDebug
)

Default log levels

View Source
const (
	ColorGood    = "good"
	ColorDanger  = "danger"
	ColorWarning = "warning"
)

Slack colors for messages

Variables

This section is empty.

Functions

func SendAlert added in v1.2.0

func SendAlert(channel, username, title, color, text string, settings LogSettings) (err error)

SendAlert sends a notification to the specified slack channel

func SetLogLevel

func SetLogLevel(level int)

SetLogLevel configures the application's log level

func SetLogger

func SetLogger(l Logger)

SetLogger sets the current logger

Types

type LogSettings added in v1.3.0

type LogSettings interface {
	GetSlackEnabled() bool
	GetHTTPClient() (client *http.Client)
	GetAppName() string
}

LogSettings interface to be implemented by other project settings.

type Logger

type Logger interface {
	Debug(v ...interface{})
	Debugf(format string, v ...interface{})
	Info(v ...interface{})
	Infof(format string, v ...interface{})
	Error(v ...interface{})
	Errorf(format string, v ...interface{})
	Fatal(v ...interface{})
	Fatalf(format string, v ...interface{})
	Print(v ...interface{})
	SetLevel(level int)
	GetLevel() int
	LogToSlack(webHook, title, text string, logSettings LogSettings)
	LogErrorToSlack(webHook, title, text string, logSettings LogSettings)
}

Logger presents a common interface for logger

func GetLogger

func GetLogger() Logger

GetLogger returns the current logger defined for the service

type SimpleLogger added in v1.2.0

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

SimpleLogger is the standar logger implementation

func NewSimpleLogger added in v1.2.0

func NewSimpleLogger() (sl *SimpleLogger)

NewSimpleLogger creates a new instance of SimpleLogger.

func (*SimpleLogger) Debug added in v1.2.0

func (sl *SimpleLogger) Debug(v ...interface{})

Debug prints the arguments to the debug logger.

func (*SimpleLogger) Debugf added in v1.2.0

func (sl *SimpleLogger) Debugf(format string, v ...interface{})

Debugf prints the arguments to the debug logger. Arguments are handled like in fmt.Printf.

func (*SimpleLogger) Error added in v1.2.0

func (sl *SimpleLogger) Error(v ...interface{})

Error prints the arguments to the error logger.

func (*SimpleLogger) Errorf added in v1.2.0

func (sl *SimpleLogger) Errorf(format string, v ...interface{})

Errorf prints the arguments to the error logger. Arguments are handled like in fmt.Printf.

func (*SimpleLogger) Fatal added in v1.2.0

func (sl *SimpleLogger) Fatal(v ...interface{})

Fatal prints the arguments to the error logger, followed by a call to os.Exit(1).

func (*SimpleLogger) Fatalf added in v1.2.0

func (sl *SimpleLogger) Fatalf(format string, v ...interface{})

Fatalf prints the arguments to the error logger, followed by a call to os.Exit(1). Arguments are handled like in fmt.Printf.

func (*SimpleLogger) GetLevel added in v1.2.0

func (sl *SimpleLogger) GetLevel() int

GetLevel returns the current log level

func (*SimpleLogger) Info added in v1.2.0

func (sl *SimpleLogger) Info(v ...interface{})

Info prints the arguments to the info logger.

func (*SimpleLogger) Infof added in v1.2.0

func (sl *SimpleLogger) Infof(format string, v ...interface{})

Infof prints the arguments to the info logger. Arguments are handled like in fmt.Printf.

func (*SimpleLogger) LogErrorToSlack added in v1.2.0

func (sl *SimpleLogger) LogErrorToSlack(webHook, title, text string, logSettings LogSettings)

LogErrorToSlack sends a message formatted as error to the configured channel, if it's enabled

func (*SimpleLogger) LogToSlack added in v1.2.0

func (sl *SimpleLogger) LogToSlack(webHook, title, text string, logSettings LogSettings)

LogToSlack sends a message to the configured channel, if it's enabled

func (*SimpleLogger) Print added in v1.2.0

func (sl *SimpleLogger) Print(v ...interface{})

Print prints the arguemtns to the info logger. It's good for standar logger compatibility

func (*SimpleLogger) SetLevel added in v1.2.0

func (sl *SimpleLogger) SetLevel(level int)

SetLevel sets the log level (0=ERROR, 1=INFO, 2=DEBUG)

Jump to

Keyboard shortcuts

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