Documentation ¶
Overview ¶
Package logger of the Tideland Go Library provides a flexible way to log information with different levels and on different backends.
The levels are Debug, Info, Warning, Error, Critical, and Fatal. Here logger.Debugf() also logs information about file name, function name, and line number while logger.Fatalf() may end the program depending on the set FatalExiterFunc.
Different backends may be set. The standard logger writes to an io.Writer (initially os.Stdout), the go logger uses the Go log package, and the sys logger uses the Go syslog package on the according operating systems. For testing the test logger exists. When created also a fetch function is return. It returns the logged strings which can be used inside of tests then.
Changes to the standard behavior can be made with logger.SetLevel(), logger.SetLogger(), and logger.SetFatalExiter(). Own logger backends and exiter can be defined.
Index ¶
- func Criticalf(format string, args ...interface{})
- func Debugf(format string, args ...interface{})
- func Errorf(format string, args ...interface{})
- func Fatalf(format string, args ...interface{})
- func Infof(format string, args ...interface{})
- func OsFatalExiter()
- func PanicFatalExiter()
- func Warningf(format string, args ...interface{})
- type FatalExiterFunc
- type FilterFunc
- type LogLevel
- type Logger
- type SysLogger
- type TestLogger
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 Fatalf ¶
func Fatalf(format string, args ...interface{})
Fatalf logs a message independent 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 OsFatalExiter ¶
func OsFatalExiter()
OsFatalExiter exits the application with os.Exit and the return code -1.
func PanicFatalExiter ¶
func PanicFatalExiter()
PanicFatalExiter exits the application with a panic.
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 ¶
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 LogLevel ¶
type LogLevel int
LogLevel describes the chosen log level between debug and critical.
Log levels to control the logging output.
func SetLevelString ¶
SetLevelString switches to a new log level passed as string. Accepted are the values "debug", "info", "warning" "error", "critical", and "fatal". The passed string will be set to lower-case. The function is intended to be used when then log level is read out of a configuration.
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 ¶
NewStandardLogger creates the standard logger writing to the passed output.
func NewSysLogger ¶
NewSysLogger returns a logger implementation using the Go syslog package.
func NewTimeformatLogger ¶
NewTimeformatLogger creates a logger writing to the passed output and with the time formatted with the passed time format.
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.
type TestLogger ¶
type TestLogger interface { Logger // Len returns the number of collected entries. Len() int // Entries returns the collected entries. Entries() []string // Reset clears the collected entries. Reset() }
TestLogger extends the Logger interface with methods to retrieve and reset the collected data.
func NewTestLogger ¶
func NewTestLogger() TestLogger
NewTestLogger returns a special logger for testing.