logger

package
v0.0.0-...-a2846b3 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2016 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

The Tideland Go Library logger package provides a flexible way to log information with different levels and on different backends.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Criticalf

func Criticalf(format string, args ...interface{})

Criticalf logs a message at critical level.

func Debugf

func Debugf(format string, args ...interface{})

Debugf logs a message at debug level.

func Errorf

func Errorf(format string, args ...interface{})

Errorf logs a message at error level.

func Fatalf

func Fatalf(format string, args ...interface{})

Fatalf logs a message independant of any level. After logging the message the functions calls the fatal exiter function, which by default means exiting the application with error code -1.

func Infof

func Infof(format string, args ...interface{})

Infof logs a message at info level.

func OsFatalExiter

func OsFatalExiter()

OsFatalExiter exits the application with os.Exit and the return code -1.

func PackageVersion

func PackageVersion() version.Version

PackageVersion returns the version of the version package.

func PanicFatalExiter

func PanicFatalExiter()

PanacFatalExiter exits the application with a panic.

func SetLogger

func SetLogger(l Logger)

SetLogger sets a new logger.

func Warningf

func Warningf(format string, args ...interface{})

Warningf logs a message at warning level.

Types

type FatalExiterFunc

type FatalExiterFunc func()

FatalExiterFunc defines a functions that will be called in case of a Fatalf call.

func SetFatalExiter

func SetFatalExiter(fef FatalExiterFunc) FatalExiterFunc

SetFatalExiter sets the fatal exiter function and returns the current one.

type FilterFunc

type FilterFunc func(level LogLevel, info, msg string) bool

FilterFunc allows to filter the output of the logging. Filters have to return true if the received entry shall be filtered and not output.

func SetFilter

func SetFilter(ff FilterFunc) FilterFunc

SetFilter sets the global output filter and returns the current one.

func UnsetFilter

func UnsetFilter() FilterFunc

UnsetFilter removes the global output folter and returns the current one.

type GoLogger

type GoLogger struct{}

GoLogger just uses the standard go log package.

func (*GoLogger) Critical

func (gl *GoLogger) Critical(info, msg string)

Critical is specified on the Logger interface.

func (*GoLogger) Debug

func (gl *GoLogger) Debug(info, msg string)

Debug is specified on the Logger interface.

func (*GoLogger) Error

func (gl *GoLogger) Error(info, msg string)

Error is specified on the Logger interface.

func (*GoLogger) Fatal

func (gl *GoLogger) Fatal(info, msg string)

Fatal is specified on the Logger interface.

func (*GoLogger) Info

func (gl *GoLogger) Info(info, msg string)

Info is specified on the Logger interface.

func (*GoLogger) Warning

func (gl *GoLogger) Warning(info, msg string)

Warning is specified on the Logger interface.

type LogLevel

type LogLevel int

LogLevel describes the chosen log level between debug and critical.

const (
	LevelDebug LogLevel = iota
	LevelInfo
	LevelWarning
	LevelError
	LevelCritical
	LevelFatal
)

Log levels to control the logging output.

func Level

func Level() LogLevel

Level returns the current log level.

func SetLevel

func SetLevel(level LogLevel) LogLevel

SetLevel switches to a new log level and returns the current one.

type Logger

type Logger interface {
	// Debug logs a debugging message.
	Debug(info, msg string)

	// Info logs an informational message.
	Info(info, msg string)

	// Warning logs a warning message.
	Warning(info, msg string)

	// Error logs an error message.
	Error(info, msg string)

	// Critical logs a critical error message.
	Critical(info, msg string)

	// Fatal logs a fatal error message.
	Fatal(info, msg string)
}

Logger is the interface for different logger backends.

func NewGoLogger

func NewGoLogger() Logger

NewGoLogger returns a logger implementation using the Go log package.

func NewStandardLogger

func NewStandardLogger(out io.Writer) Logger

NewStandardLogger creates the standard logger writing to the passed output.

func NewSysLogger

func NewSysLogger(tag string) (Logger, error)

NewGoLogger returns a logger implementation using the Go syslog package.

func NewTimeformatLogger

func NewTimeformatLogger(out io.Writer, timeFormat string) Logger

NewTimeformatLogger creates a logger writing to the passed output and with the time formatted with the passed time format.

type StandardLogger

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

StandardLogger is a simple logger writing to the given writer. Beside the output it doesn't handle the levels differently.

func (*StandardLogger) Critical

func (sl *StandardLogger) Critical(info, msg string)

Critical is specified on the Logger interface.

func (*StandardLogger) Debug

func (sl *StandardLogger) Debug(info, msg string)

Debug is specified on the Logger interface.

func (*StandardLogger) Error

func (sl *StandardLogger) Error(info, msg string)

Error is specified on the Logger interface.

func (*StandardLogger) Fatal

func (sl *StandardLogger) Fatal(info, msg string)

Fatal is specified on the Logger interface.

func (*StandardLogger) Info

func (sl *StandardLogger) Info(info, msg string)

Info is specified on the Logger interface.

func (*StandardLogger) Warning

func (sl *StandardLogger) Warning(info, msg string)

Warning is specified on the Logger interface.

type SysLogger

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

SysLogger uses the Go syslog package as logging backend. It does not work on Windows or Plan9.

func (*SysLogger) Critical

func (sl *SysLogger) Critical(info, msg string)

Critical is specified on the Logger interface.

func (*SysLogger) Debug

func (sl *SysLogger) Debug(info, msg string)

Debug is specified on the Logger interface.

func (*SysLogger) Error

func (sl *SysLogger) Error(info, msg string)

Error is specified on the Logger interface.

func (*SysLogger) Fatal

func (sl *SysLogger) Fatal(info, msg string)

Fatal is specified on the Logger interface.

func (*SysLogger) Info

func (sl *SysLogger) Info(info, msg string)

Info is specified on the Logger interface.

func (*SysLogger) Warning

func (sl *SysLogger) Warning(info, msg string)

Warning is specified on the Logger interface.

Jump to

Keyboard shortcuts

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